5 #include "src/debug/debug-type-profile.h" 7 #include "src/feedback-vector.h" 8 #include "src/isolate.h" 9 #include "src/objects-inl.h" 10 #include "src/objects.h" 15 std::unique_ptr<TypeProfile> TypeProfile::Collect(Isolate* isolate) {
16 std::unique_ptr<TypeProfile> result(
new TypeProfile());
19 DCHECK(isolate->factory()
20 ->feedback_vectors_for_profiling_tools()
22 Handle<ArrayList> list = Handle<ArrayList>::cast(
23 isolate->factory()->feedback_vectors_for_profiling_tools());
25 Script::Iterator scripts(isolate);
27 while (Script* script = scripts.Next()) {
28 if (!script->IsUserJavaScript()) {
32 Handle<Script> script_handle(script, isolate);
34 TypeProfileScript type_profile_script(script_handle);
35 std::vector<TypeProfileEntry>* entries = &type_profile_script.entries;
39 for (
int i = 0;
i < list->Length();
i++) {
40 FeedbackVector* vector = FeedbackVector::cast(list->Get(
i));
41 SharedFunctionInfo* info = vector->shared_function_info();
42 DCHECK(info->IsSubjectToDebugging());
45 if (script != info->script()) {
48 if (info->feedback_metadata()->is_empty() ||
49 !info->feedback_metadata()->HasTypeProfileSlot()) {
52 FeedbackSlot slot = vector->GetTypeProfileSlot();
53 FeedbackNexus nexus(vector, slot);
54 Handle<String> name(info->DebugName(), isolate);
55 std::vector<int> source_positions = nexus.GetSourcePositions();
56 for (
int position : source_positions) {
57 DCHECK_GE(position, 0);
58 entries->emplace_back(position, nexus.GetTypesForSourcePositions(
59 static_cast<uint32_t>(position)));
63 nexus.ResetTypeProfile();
65 if (!entries->empty()) {
66 result->emplace_back(type_profile_script);
72 void TypeProfile::SelectMode(Isolate* isolate, debug::TypeProfile::Mode mode) {
73 HandleScope handle_scope(isolate);
75 if (mode == debug::TypeProfile::Mode::kNone) {
76 if (!isolate->factory()
77 ->feedback_vectors_for_profiling_tools()
78 ->IsUndefined(isolate)) {
82 DCHECK(isolate->factory()
83 ->feedback_vectors_for_profiling_tools()
85 Handle<ArrayList> list = Handle<ArrayList>::cast(
86 isolate->factory()->feedback_vectors_for_profiling_tools());
88 for (
int i = 0;
i < list->Length();
i++) {
89 FeedbackVector* vector = FeedbackVector::cast(list->Get(
i));
90 SharedFunctionInfo* info = vector->shared_function_info();
91 DCHECK(info->IsSubjectToDebugging());
92 if (info->feedback_metadata()->HasTypeProfileSlot()) {
93 FeedbackSlot slot = vector->GetTypeProfileSlot();
94 FeedbackNexus nexus(vector, slot);
95 nexus.ResetTypeProfile();
101 if (isolate->is_best_effort_code_coverage()) {
102 isolate->SetFeedbackVectorsForProfilingTools(
103 ReadOnlyRoots(isolate).undefined_value());
107 DCHECK_EQ(debug::TypeProfile::Mode::kCollect, mode);
108 isolate->MaybeInitializeVectorListFromHeap();
110 isolate->set_type_profile_mode(mode);