OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 14592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14603 // This test breaks because InstallGetter (function from snapshot that | 14603 // This test breaks because InstallGetter (function from snapshot that |
14604 // only gets called from experimental natives) is compiled with entry hooks. | 14604 // only gets called from experimental natives) is compiled with entry hooks. |
14605 i::FLAG_allow_natives_syntax = true; | 14605 i::FLAG_allow_natives_syntax = true; |
14606 i::FLAG_turbo_inlining = false; | 14606 i::FLAG_turbo_inlining = false; |
14607 i::FLAG_use_inlining = false; | 14607 i::FLAG_use_inlining = false; |
14608 | 14608 |
14609 SetFunctionEntryHookTest test; | 14609 SetFunctionEntryHookTest test; |
14610 test.RunTest(); | 14610 test.RunTest(); |
14611 } | 14611 } |
14612 | 14612 |
14613 | 14613 static v8::base::HashMap* code_map = NULL; |
14614 static i::HashMap* code_map = NULL; | 14614 static v8::base::HashMap* jitcode_line_info = NULL; |
14615 static i::HashMap* jitcode_line_info = NULL; | |
14616 static int saw_bar = 0; | 14615 static int saw_bar = 0; |
14617 static int move_events = 0; | 14616 static int move_events = 0; |
14618 | 14617 |
14619 | 14618 |
14620 static bool FunctionNameIs(const char* expected, | 14619 static bool FunctionNameIs(const char* expected, |
14621 const v8::JitCodeEvent* event) { | 14620 const v8::JitCodeEvent* event) { |
14622 // Log lines for functions are of the general form: | 14621 // Log lines for functions are of the general form: |
14623 // "LazyCompile:<type><function_name>" or Function:<type><function_name>, | 14622 // "LazyCompile:<type><function_name>" or Function:<type><function_name>, |
14624 // where the type is one of "*", "~" or "". | 14623 // where the type is one of "*", "~" or "". |
14625 static const char* kPreamble; | 14624 static const char* kPreamble; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14665 CHECK(jitcode_line_info != NULL); | 14664 CHECK(jitcode_line_info != NULL); |
14666 | 14665 |
14667 class DummyJitCodeLineInfo { | 14666 class DummyJitCodeLineInfo { |
14668 }; | 14667 }; |
14669 | 14668 |
14670 switch (event->type) { | 14669 switch (event->type) { |
14671 case v8::JitCodeEvent::CODE_ADDED: { | 14670 case v8::JitCodeEvent::CODE_ADDED: { |
14672 CHECK(event->code_start != NULL); | 14671 CHECK(event->code_start != NULL); |
14673 CHECK_NE(0, static_cast<int>(event->code_len)); | 14672 CHECK_NE(0, static_cast<int>(event->code_len)); |
14674 CHECK(event->name.str != NULL); | 14673 CHECK(event->name.str != NULL); |
14675 i::HashMap::Entry* entry = code_map->LookupOrInsert( | 14674 v8::base::HashMap::Entry* entry = code_map->LookupOrInsert( |
14676 event->code_start, i::ComputePointerHash(event->code_start)); | 14675 event->code_start, i::ComputePointerHash(event->code_start)); |
14677 entry->value = reinterpret_cast<void*>(event->code_len); | 14676 entry->value = reinterpret_cast<void*>(event->code_len); |
14678 | 14677 |
14679 if (FunctionNameIs("bar", event)) { | 14678 if (FunctionNameIs("bar", event)) { |
14680 ++saw_bar; | 14679 ++saw_bar; |
14681 } | 14680 } |
14682 } | 14681 } |
14683 break; | 14682 break; |
14684 | 14683 |
14685 case v8::JitCodeEvent::CODE_MOVED: { | 14684 case v8::JitCodeEvent::CODE_MOVED: { |
14686 uint32_t hash = i::ComputePointerHash(event->code_start); | 14685 uint32_t hash = i::ComputePointerHash(event->code_start); |
14687 // We would like to never see code move that we haven't seen before, | 14686 // We would like to never see code move that we haven't seen before, |
14688 // but the code creation event does not happen until the line endings | 14687 // but the code creation event does not happen until the line endings |
14689 // have been calculated (this is so that we can report the line in the | 14688 // have been calculated (this is so that we can report the line in the |
14690 // script at which the function source is found, see | 14689 // script at which the function source is found, see |
14691 // Compiler::RecordFunctionCompilation) and the line endings | 14690 // Compiler::RecordFunctionCompilation) and the line endings |
14692 // calculations can cause a GC, which can move the newly created code | 14691 // calculations can cause a GC, which can move the newly created code |
14693 // before its existence can be logged. | 14692 // before its existence can be logged. |
14694 i::HashMap::Entry* entry = code_map->Lookup(event->code_start, hash); | 14693 v8::base::HashMap::Entry* entry = |
| 14694 code_map->Lookup(event->code_start, hash); |
14695 if (entry != NULL) { | 14695 if (entry != NULL) { |
14696 ++move_events; | 14696 ++move_events; |
14697 | 14697 |
14698 CHECK_EQ(reinterpret_cast<void*>(event->code_len), entry->value); | 14698 CHECK_EQ(reinterpret_cast<void*>(event->code_len), entry->value); |
14699 code_map->Remove(event->code_start, hash); | 14699 code_map->Remove(event->code_start, hash); |
14700 | 14700 |
14701 entry = code_map->LookupOrInsert( | 14701 entry = code_map->LookupOrInsert( |
14702 event->new_code_start, | 14702 event->new_code_start, |
14703 i::ComputePointerHash(event->new_code_start)); | 14703 i::ComputePointerHash(event->new_code_start)); |
14704 entry->value = reinterpret_cast<void*>(event->code_len); | 14704 entry->value = reinterpret_cast<void*>(event->code_len); |
14705 } | 14705 } |
14706 } | 14706 } |
14707 break; | 14707 break; |
14708 | 14708 |
14709 case v8::JitCodeEvent::CODE_REMOVED: | 14709 case v8::JitCodeEvent::CODE_REMOVED: |
14710 // Object/code removal events are currently not dispatched from the GC. | 14710 // Object/code removal events are currently not dispatched from the GC. |
14711 CHECK(false); | 14711 CHECK(false); |
14712 break; | 14712 break; |
14713 | 14713 |
14714 // For CODE_START_LINE_INFO_RECORDING event, we will create one | 14714 // For CODE_START_LINE_INFO_RECORDING event, we will create one |
14715 // DummyJitCodeLineInfo data structure pointed by event->user_dat. We | 14715 // DummyJitCodeLineInfo data structure pointed by event->user_dat. We |
14716 // record it in jitcode_line_info. | 14716 // record it in jitcode_line_info. |
14717 case v8::JitCodeEvent::CODE_START_LINE_INFO_RECORDING: { | 14717 case v8::JitCodeEvent::CODE_START_LINE_INFO_RECORDING: { |
14718 DummyJitCodeLineInfo* line_info = new DummyJitCodeLineInfo(); | 14718 DummyJitCodeLineInfo* line_info = new DummyJitCodeLineInfo(); |
14719 v8::JitCodeEvent* temp_event = const_cast<v8::JitCodeEvent*>(event); | 14719 v8::JitCodeEvent* temp_event = const_cast<v8::JitCodeEvent*>(event); |
14720 temp_event->user_data = line_info; | 14720 temp_event->user_data = line_info; |
14721 i::HashMap::Entry* entry = jitcode_line_info->LookupOrInsert( | 14721 v8::base::HashMap::Entry* entry = jitcode_line_info->LookupOrInsert( |
14722 line_info, i::ComputePointerHash(line_info)); | 14722 line_info, i::ComputePointerHash(line_info)); |
14723 entry->value = reinterpret_cast<void*>(line_info); | 14723 entry->value = reinterpret_cast<void*>(line_info); |
14724 } | 14724 } |
14725 break; | 14725 break; |
14726 // For these two events, we will check whether the event->user_data | 14726 // For these two events, we will check whether the event->user_data |
14727 // data structure is created before during CODE_START_LINE_INFO_RECORDING | 14727 // data structure is created before during CODE_START_LINE_INFO_RECORDING |
14728 // event. And delete it in CODE_END_LINE_INFO_RECORDING event handling. | 14728 // event. And delete it in CODE_END_LINE_INFO_RECORDING event handling. |
14729 case v8::JitCodeEvent::CODE_END_LINE_INFO_RECORDING: { | 14729 case v8::JitCodeEvent::CODE_END_LINE_INFO_RECORDING: { |
14730 CHECK(event->user_data != NULL); | 14730 CHECK(event->user_data != NULL); |
14731 uint32_t hash = i::ComputePointerHash(event->user_data); | 14731 uint32_t hash = i::ComputePointerHash(event->user_data); |
14732 i::HashMap::Entry* entry = | 14732 v8::base::HashMap::Entry* entry = |
14733 jitcode_line_info->Lookup(event->user_data, hash); | 14733 jitcode_line_info->Lookup(event->user_data, hash); |
14734 CHECK(entry != NULL); | 14734 CHECK(entry != NULL); |
14735 delete reinterpret_cast<DummyJitCodeLineInfo*>(event->user_data); | 14735 delete reinterpret_cast<DummyJitCodeLineInfo*>(event->user_data); |
14736 } | 14736 } |
14737 break; | 14737 break; |
14738 | 14738 |
14739 case v8::JitCodeEvent::CODE_ADD_LINE_POS_INFO: { | 14739 case v8::JitCodeEvent::CODE_ADD_LINE_POS_INFO: { |
14740 CHECK(event->user_data != NULL); | 14740 CHECK(event->user_data != NULL); |
14741 uint32_t hash = i::ComputePointerHash(event->user_data); | 14741 uint32_t hash = i::ComputePointerHash(event->user_data); |
14742 i::HashMap::Entry* entry = | 14742 v8::base::HashMap::Entry* entry = |
14743 jitcode_line_info->Lookup(event->user_data, hash); | 14743 jitcode_line_info->Lookup(event->user_data, hash); |
14744 CHECK(entry != NULL); | 14744 CHECK(entry != NULL); |
14745 } | 14745 } |
14746 break; | 14746 break; |
14747 | 14747 |
14748 default: | 14748 default: |
14749 // Impossible event. | 14749 // Impossible event. |
14750 CHECK(false); | 14750 CHECK(false); |
14751 break; | 14751 break; |
14752 } | 14752 } |
(...skipping 21 matching lines...) Expand all Loading... |
14774 v8::Isolate* isolate = v8::Isolate::New(create_params); | 14774 v8::Isolate* isolate = v8::Isolate::New(create_params); |
14775 isolate->Enter(); | 14775 isolate->Enter(); |
14776 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 14776 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
14777 i::Heap* heap = i_isolate->heap(); | 14777 i::Heap* heap = i_isolate->heap(); |
14778 | 14778 |
14779 // Start with a clean slate. | 14779 // Start with a clean slate. |
14780 heap->CollectAllAvailableGarbage("TestSetJitCodeEventHandler_Prepare"); | 14780 heap->CollectAllAvailableGarbage("TestSetJitCodeEventHandler_Prepare"); |
14781 | 14781 |
14782 { | 14782 { |
14783 v8::HandleScope scope(isolate); | 14783 v8::HandleScope scope(isolate); |
14784 i::HashMap code(MatchPointers); | 14784 v8::base::HashMap code(MatchPointers); |
14785 code_map = &code; | 14785 code_map = &code; |
14786 | 14786 |
14787 i::HashMap lineinfo(MatchPointers); | 14787 v8::base::HashMap lineinfo(MatchPointers); |
14788 jitcode_line_info = &lineinfo; | 14788 jitcode_line_info = &lineinfo; |
14789 | 14789 |
14790 saw_bar = 0; | 14790 saw_bar = 0; |
14791 move_events = 0; | 14791 move_events = 0; |
14792 | 14792 |
14793 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); | 14793 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); |
14794 | 14794 |
14795 // Generate new code objects sparsely distributed across several | 14795 // Generate new code objects sparsely distributed across several |
14796 // different fragmented code-space pages. | 14796 // different fragmented code-space pages. |
14797 const int kIterations = 10; | 14797 const int kIterations = 10; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14840 isolate->Enter(); | 14840 isolate->Enter(); |
14841 | 14841 |
14842 // Verify that we get callbacks for existing code objects when we | 14842 // Verify that we get callbacks for existing code objects when we |
14843 // request enumeration of existing code. | 14843 // request enumeration of existing code. |
14844 { | 14844 { |
14845 v8::HandleScope scope(isolate); | 14845 v8::HandleScope scope(isolate); |
14846 LocalContext env(isolate); | 14846 LocalContext env(isolate); |
14847 CompileRun(script); | 14847 CompileRun(script); |
14848 | 14848 |
14849 // Now get code through initial iteration. | 14849 // Now get code through initial iteration. |
14850 i::HashMap code(MatchPointers); | 14850 v8::base::HashMap code(MatchPointers); |
14851 code_map = &code; | 14851 code_map = &code; |
14852 | 14852 |
14853 i::HashMap lineinfo(MatchPointers); | 14853 v8::base::HashMap lineinfo(MatchPointers); |
14854 jitcode_line_info = &lineinfo; | 14854 jitcode_line_info = &lineinfo; |
14855 | 14855 |
14856 isolate->SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, | 14856 isolate->SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, |
14857 event_handler); | 14857 event_handler); |
14858 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | 14858 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); |
14859 | 14859 |
14860 jitcode_line_info = NULL; | 14860 jitcode_line_info = NULL; |
14861 // We expect that we got some events. Note that if we could get code removal | 14861 // We expect that we got some events. Note that if we could get code removal |
14862 // notifications, we could compare two collections, one created by listening | 14862 // notifications, we could compare two collections, one created by listening |
14863 // from the time of creation of an isolate, and the other by subscribing | 14863 // from the time of creation of an isolate, and the other by subscribing |
(...skipping 10376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25240 } | 25240 } |
25241 | 25241 |
25242 TEST(PrivateForApiIsNumber) { | 25242 TEST(PrivateForApiIsNumber) { |
25243 LocalContext context; | 25243 LocalContext context; |
25244 v8::Isolate* isolate = CcTest::isolate(); | 25244 v8::Isolate* isolate = CcTest::isolate(); |
25245 v8::HandleScope scope(isolate); | 25245 v8::HandleScope scope(isolate); |
25246 | 25246 |
25247 // Shouldn't crash. | 25247 // Shouldn't crash. |
25248 v8::Private::ForApi(isolate, v8_str("42")); | 25248 v8::Private::ForApi(isolate, v8_str("42")); |
25249 } | 25249 } |
OLD | NEW |