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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "lib/stacktrace.h" | 10 #include "lib/stacktrace.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 | 73 |
74 const char* CanonicalFunction(const char* func) { | 74 const char* CanonicalFunction(const char* func) { |
75 if (strncmp(func, "dart::", 6) == 0) { | 75 if (strncmp(func, "dart::", 6) == 0) { |
76 return func + 6; | 76 return func + 6; |
77 } else { | 77 } else { |
78 return func; | 78 return func; |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
| 82 #ifndef PRODUCT |
82 #define API_TIMELINE_DURATION \ | 83 #define API_TIMELINE_DURATION \ |
83 TimelineDurationScope tds(Thread::Current(), \ | 84 TimelineDurationScope tds(Thread::Current(), \ |
84 Timeline::GetVMApiStream(), \ | 85 Timeline::GetVMApiStream(), \ |
85 CURRENT_FUNC) | 86 CURRENT_FUNC) |
86 | 87 |
87 #define API_TIMELINE_BEGIN_END \ | 88 #define API_TIMELINE_BEGIN_END \ |
88 TimelineBeginEndScope tbes(Thread::Current(), \ | 89 TimelineBeginEndScope tbes(Thread::Current(), \ |
89 Timeline::GetVMApiStream(), \ | 90 Timeline::GetVMApiStream(), \ |
90 CURRENT_FUNC) | 91 CURRENT_FUNC) |
91 | 92 #else |
| 93 #define API_TIMELINE_DURATION do { } while (false) |
| 94 #define API_TIMELINE_BEGIN_END do { } while (false) |
| 95 #endif // !PRODUCT |
92 | 96 |
93 #if defined(DEBUG) | 97 #if defined(DEBUG) |
94 // An object visitor which will iterate over all the function objects in the | 98 // An object visitor which will iterate over all the function objects in the |
95 // heap and check if the result type and parameter types are canonicalized | 99 // heap and check if the result type and parameter types are canonicalized |
96 // or not. An assertion is raised if a type is not canonicalized. | 100 // or not. An assertion is raised if a type is not canonicalized. |
97 class FunctionVisitor : public ObjectVisitor { | 101 class FunctionVisitor : public ObjectVisitor { |
98 public: | 102 public: |
99 explicit FunctionVisitor(Thread* thread) : | 103 explicit FunctionVisitor(Thread* thread) : |
100 ObjectVisitor(thread->isolate()), | 104 ObjectVisitor(thread->isolate()), |
101 classHandle_(Class::Handle(thread->zone())), | 105 classHandle_(Class::Handle(thread->zone())), |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 Thread* T = Thread::Current(); | 1252 Thread* T = Thread::Current(); |
1249 StackZone zone(T); | 1253 StackZone zone(T); |
1250 HANDLESCOPE(T); | 1254 HANDLESCOPE(T); |
1251 // We enter an API scope here as InitializeIsolate could compile some | 1255 // We enter an API scope here as InitializeIsolate could compile some |
1252 // bootstrap library files which call out to a tag handler that may create | 1256 // bootstrap library files which call out to a tag handler that may create |
1253 // Api Handles when an error is encountered. | 1257 // Api Handles when an error is encountered. |
1254 Dart_EnterScope(); | 1258 Dart_EnterScope(); |
1255 const Error& error_obj = | 1259 const Error& error_obj = |
1256 Error::Handle(Z, Dart::InitializeIsolate(snapshot, callback_data)); | 1260 Error::Handle(Z, Dart::InitializeIsolate(snapshot, callback_data)); |
1257 if (error_obj.IsNull()) { | 1261 if (error_obj.IsNull()) { |
1258 #if defined(DART_NO_SNAPSHOT) | 1262 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) |
1259 if (FLAG_check_function_fingerprints) { | 1263 if (FLAG_check_function_fingerprints) { |
1260 Library::CheckFunctionFingerprints(); | 1264 Library::CheckFunctionFingerprints(); |
1261 } | 1265 } |
1262 #endif // defined(DART_NO_SNAPSHOT). | 1266 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). |
1263 // We exit the API scope entered above. | 1267 // We exit the API scope entered above. |
1264 Dart_ExitScope(); | 1268 Dart_ExitScope(); |
1265 // A Thread structure has been associated to the thread, we do the | 1269 // A Thread structure has been associated to the thread, we do the |
1266 // safepoint transition explicity here instead of using the | 1270 // safepoint transition explicity here instead of using the |
1267 // TransitionXXX scope objects as the reverse transition happens | 1271 // TransitionXXX scope objects as the reverse transition happens |
1268 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. | 1272 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. |
1269 T->set_execution_state(Thread::kThreadInNative); | 1273 T->set_execution_state(Thread::kThreadInNative); |
1270 T->EnterSafepoint(); | 1274 T->EnterSafepoint(); |
1271 return Api::CastIsolate(I); | 1275 return Api::CastIsolate(I); |
1272 } | 1276 } |
(...skipping 4451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5724 #endif // PRODUCT | 5728 #endif // PRODUCT |
5725 } | 5729 } |
5726 | 5730 |
5727 | 5731 |
5728 DART_EXPORT int64_t Dart_TimelineGetMicros() { | 5732 DART_EXPORT int64_t Dart_TimelineGetMicros() { |
5729 return OS::GetCurrentMonotonicMicros(); | 5733 return OS::GetCurrentMonotonicMicros(); |
5730 } | 5734 } |
5731 | 5735 |
5732 | 5736 |
5733 DART_EXPORT void Dart_TimelineSetRecordedStreams(int64_t stream_mask) { | 5737 DART_EXPORT void Dart_TimelineSetRecordedStreams(int64_t stream_mask) { |
| 5738 if (!FLAG_support_timeline) { |
| 5739 return; |
| 5740 } |
5734 Isolate* isolate = Isolate::Current(); | 5741 Isolate* isolate = Isolate::Current(); |
5735 CHECK_ISOLATE(isolate); | 5742 CHECK_ISOLATE(isolate); |
5736 isolate->GetAPIStream()->set_enabled( | 5743 isolate->GetAPIStream()->set_enabled( |
5737 (stream_mask & DART_TIMELINE_STREAM_API) != 0); | 5744 (stream_mask & DART_TIMELINE_STREAM_API) != 0); |
5738 isolate->GetCompilerStream()->set_enabled( | 5745 isolate->GetCompilerStream()->set_enabled( |
5739 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0); | 5746 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0); |
5740 isolate->GetDartStream()->set_enabled( | 5747 isolate->GetDartStream()->set_enabled( |
5741 (stream_mask & DART_TIMELINE_STREAM_DART) != 0); | 5748 (stream_mask & DART_TIMELINE_STREAM_DART) != 0); |
5742 isolate->GetDebuggerStream()->set_enabled( | 5749 isolate->GetDebuggerStream()->set_enabled( |
5743 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0); | 5750 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0); |
5744 isolate->GetEmbedderStream()->set_enabled( | 5751 isolate->GetEmbedderStream()->set_enabled( |
5745 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0); | 5752 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0); |
5746 isolate->GetGCStream()->set_enabled( | 5753 isolate->GetGCStream()->set_enabled( |
5747 (stream_mask & DART_TIMELINE_STREAM_GC) != 0); | 5754 (stream_mask & DART_TIMELINE_STREAM_GC) != 0); |
5748 isolate->GetIsolateStream()->set_enabled( | 5755 isolate->GetIsolateStream()->set_enabled( |
5749 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0); | 5756 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0); |
5750 } | 5757 } |
5751 | 5758 |
5752 | 5759 |
5753 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { | 5760 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { |
5754 // Per isolate overrides. | 5761 // Per isolate overrides. |
| 5762 if (!FLAG_support_timeline) { |
| 5763 return; |
| 5764 } |
5755 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; | 5765 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; |
5756 const bool compiler_enabled = | 5766 const bool compiler_enabled = |
5757 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; | 5767 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; |
5758 const bool dart_enabled = | 5768 const bool dart_enabled = |
5759 (stream_mask & DART_TIMELINE_STREAM_DART) != 0; | 5769 (stream_mask & DART_TIMELINE_STREAM_DART) != 0; |
5760 const bool debugger_enabled = | 5770 const bool debugger_enabled = |
5761 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0; | 5771 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0; |
5762 const bool embedder_enabled = | 5772 const bool embedder_enabled = |
5763 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; | 5773 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; |
5764 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; | 5774 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5923 JSONStream js; | 5933 JSONStream js; |
5924 TimelineEventFilter filter; | 5934 TimelineEventFilter filter; |
5925 timeline_recorder->PrintTraceEvent(&js, &filter); | 5935 timeline_recorder->PrintTraceEvent(&js, &filter); |
5926 return StreamTraceEvents(consumer, user_data, &js); | 5936 return StreamTraceEvents(consumer, user_data, &js); |
5927 } | 5937 } |
5928 | 5938 |
5929 | 5939 |
5930 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, | 5940 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, |
5931 int64_t start_micros, | 5941 int64_t start_micros, |
5932 int64_t end_micros) { | 5942 int64_t end_micros) { |
| 5943 if (!FLAG_support_timeline) { |
| 5944 return Api::Success(); |
| 5945 } |
5933 Isolate* isolate = Isolate::Current(); | 5946 Isolate* isolate = Isolate::Current(); |
5934 CHECK_ISOLATE(isolate); | 5947 CHECK_ISOLATE(isolate); |
5935 if (label == NULL) { | 5948 if (label == NULL) { |
5936 RETURN_NULL_ERROR(label); | 5949 RETURN_NULL_ERROR(label); |
5937 } | 5950 } |
5938 if (start_micros > end_micros) { | 5951 if (start_micros > end_micros) { |
5939 const char* msg = "%s: start_micros must be <= end_micros"; | 5952 const char* msg = "%s: start_micros must be <= end_micros"; |
5940 return Api::NewError(msg, CURRENT_FUNC); | 5953 return Api::NewError(msg, CURRENT_FUNC); |
5941 } | 5954 } |
5942 TimelineStream* stream = isolate->GetEmbedderStream(); | 5955 TimelineStream* stream = isolate->GetEmbedderStream(); |
5943 ASSERT(stream != NULL); | 5956 ASSERT(stream != NULL); |
5944 TimelineEvent* event = stream->StartEvent(); | 5957 TimelineEvent* event = stream->StartEvent(); |
5945 if (event != NULL) { | 5958 if (event != NULL) { |
5946 event->Duration(label, start_micros, end_micros); | 5959 event->Duration(label, start_micros, end_micros); |
5947 event->Complete(); | 5960 event->Complete(); |
5948 } | 5961 } |
5949 return Api::Success(); | 5962 return Api::Success(); |
5950 } | 5963 } |
5951 | 5964 |
5952 | 5965 |
5953 DART_EXPORT Dart_Handle Dart_TimelineInstant(const char* label) { | 5966 DART_EXPORT Dart_Handle Dart_TimelineInstant(const char* label) { |
| 5967 if (!FLAG_support_timeline) { |
| 5968 return Api::Success(); |
| 5969 } |
5954 Isolate* isolate = Isolate::Current(); | 5970 Isolate* isolate = Isolate::Current(); |
5955 CHECK_ISOLATE(isolate); | 5971 CHECK_ISOLATE(isolate); |
5956 if (label == NULL) { | 5972 if (label == NULL) { |
5957 RETURN_NULL_ERROR(label); | 5973 RETURN_NULL_ERROR(label); |
5958 } | 5974 } |
5959 TimelineStream* stream = isolate->GetEmbedderStream(); | 5975 TimelineStream* stream = isolate->GetEmbedderStream(); |
5960 ASSERT(stream != NULL); | 5976 ASSERT(stream != NULL); |
5961 TimelineEvent* event = stream->StartEvent(); | 5977 TimelineEvent* event = stream->StartEvent(); |
5962 if (event != NULL) { | 5978 if (event != NULL) { |
5963 event->Instant(label); | 5979 event->Instant(label); |
5964 event->Complete(); | 5980 event->Complete(); |
5965 } | 5981 } |
5966 return Api::Success(); | 5982 return Api::Success(); |
5967 } | 5983 } |
5968 | 5984 |
5969 | 5985 |
5970 DART_EXPORT Dart_Handle Dart_TimelineAsyncBegin(const char* label, | 5986 DART_EXPORT Dart_Handle Dart_TimelineAsyncBegin(const char* label, |
5971 int64_t* async_id) { | 5987 int64_t* async_id) { |
| 5988 if (!FLAG_support_timeline) { |
| 5989 return Api::Success(); |
| 5990 } |
5972 Isolate* isolate = Isolate::Current(); | 5991 Isolate* isolate = Isolate::Current(); |
5973 CHECK_ISOLATE(isolate); | 5992 CHECK_ISOLATE(isolate); |
5974 if (label == NULL) { | 5993 if (label == NULL) { |
5975 RETURN_NULL_ERROR(label); | 5994 RETURN_NULL_ERROR(label); |
5976 } | 5995 } |
5977 if (async_id == NULL) { | 5996 if (async_id == NULL) { |
5978 RETURN_NULL_ERROR(async_id); | 5997 RETURN_NULL_ERROR(async_id); |
5979 } | 5998 } |
5980 *async_id = -1; | 5999 *async_id = -1; |
5981 TimelineStream* stream = isolate->GetEmbedderStream(); | 6000 TimelineStream* stream = isolate->GetEmbedderStream(); |
5982 ASSERT(stream != NULL); | 6001 ASSERT(stream != NULL); |
5983 TimelineEvent* event = stream->StartEvent(); | 6002 TimelineEvent* event = stream->StartEvent(); |
5984 if (event != NULL) { | 6003 if (event != NULL) { |
5985 TimelineEventRecorder* recorder = Timeline::recorder(); | 6004 TimelineEventRecorder* recorder = Timeline::recorder(); |
5986 ASSERT(recorder != NULL); | 6005 ASSERT(recorder != NULL); |
5987 *async_id = recorder->GetNextAsyncId(); | 6006 *async_id = recorder->GetNextAsyncId(); |
5988 event->AsyncBegin(label, *async_id); | 6007 event->AsyncBegin(label, *async_id); |
5989 event->Complete(); | 6008 event->Complete(); |
5990 } | 6009 } |
5991 return Api::Success(); | 6010 return Api::Success(); |
5992 } | 6011 } |
5993 | 6012 |
5994 | 6013 |
5995 DART_EXPORT Dart_Handle Dart_TimelineAsyncInstant(const char* label, | 6014 DART_EXPORT Dart_Handle Dart_TimelineAsyncInstant(const char* label, |
5996 int64_t async_id) { | 6015 int64_t async_id) { |
| 6016 if (!FLAG_support_timeline) { |
| 6017 return Api::Success(); |
| 6018 } |
5997 if (async_id < 0) { | 6019 if (async_id < 0) { |
5998 return Api::Success(); | 6020 return Api::Success(); |
5999 } | 6021 } |
6000 Isolate* isolate = Isolate::Current(); | 6022 Isolate* isolate = Isolate::Current(); |
6001 CHECK_ISOLATE(isolate); | 6023 CHECK_ISOLATE(isolate); |
6002 if (label == NULL) { | 6024 if (label == NULL) { |
6003 RETURN_NULL_ERROR(label); | 6025 RETURN_NULL_ERROR(label); |
6004 } | 6026 } |
6005 TimelineStream* stream = isolate->GetEmbedderStream(); | 6027 TimelineStream* stream = isolate->GetEmbedderStream(); |
6006 ASSERT(stream != NULL); | 6028 ASSERT(stream != NULL); |
6007 TimelineEvent* event = stream->StartEvent(); | 6029 TimelineEvent* event = stream->StartEvent(); |
6008 if (event != NULL) { | 6030 if (event != NULL) { |
6009 event->AsyncInstant(label, async_id); | 6031 event->AsyncInstant(label, async_id); |
6010 event->Complete(); | 6032 event->Complete(); |
6011 } | 6033 } |
6012 return Api::Success(); | 6034 return Api::Success(); |
6013 } | 6035 } |
6014 | 6036 |
6015 | 6037 |
6016 DART_EXPORT Dart_Handle Dart_TimelineAsyncEnd(const char* label, | 6038 DART_EXPORT Dart_Handle Dart_TimelineAsyncEnd(const char* label, |
6017 int64_t async_id) { | 6039 int64_t async_id) { |
| 6040 if (!FLAG_support_timeline) { |
| 6041 return Api::Success(); |
| 6042 } |
6018 if (async_id < 0) { | 6043 if (async_id < 0) { |
6019 return Api::Success(); | 6044 return Api::Success(); |
6020 } | 6045 } |
6021 Isolate* isolate = Isolate::Current(); | 6046 Isolate* isolate = Isolate::Current(); |
6022 CHECK_ISOLATE(isolate); | 6047 CHECK_ISOLATE(isolate); |
6023 if (label == NULL) { | 6048 if (label == NULL) { |
6024 RETURN_NULL_ERROR(label); | 6049 RETURN_NULL_ERROR(label); |
6025 } | 6050 } |
6026 TimelineStream* stream = isolate->GetEmbedderStream(); | 6051 TimelineStream* stream = isolate->GetEmbedderStream(); |
6027 ASSERT(stream != NULL); | 6052 ASSERT(stream != NULL); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6132 return Api::Success(); | 6157 return Api::Success(); |
6133 } | 6158 } |
6134 #endif // DART_PRECOMPILER | 6159 #endif // DART_PRECOMPILER |
6135 | 6160 |
6136 | 6161 |
6137 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { | 6162 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { |
6138 return Dart::IsRunningPrecompiledCode(); | 6163 return Dart::IsRunningPrecompiledCode(); |
6139 } | 6164 } |
6140 | 6165 |
6141 } // namespace dart | 6166 } // namespace dart |
OLD | NEW |