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

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 725293003: don't use to-be-deprecated Value::To* without isolate parameter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-log.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 virtual const char* data() const { return data_; } 883 virtual const char* data() const { return data_; }
884 virtual size_t length() const { return length_; } 884 virtual size_t length() const { return length_; }
885 private: 885 private:
886 const char* data_; 886 const char* data_;
887 size_t length_; 887 size_t length_;
888 }; 888 };
889 889
890 } // namespace 890 } // namespace
891 891
892 TEST(HeapSnapshotJSONSerialization) { 892 TEST(HeapSnapshotJSONSerialization) {
893 v8::Isolate* isolate = CcTest::isolate();
893 LocalContext env; 894 LocalContext env;
894 v8::HandleScope scope(env->GetIsolate()); 895 v8::HandleScope scope(isolate);
895 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 896 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
896 897
897 #define STRING_LITERAL_FOR_TEST \ 898 #define STRING_LITERAL_FOR_TEST \
898 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" 899 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\""
899 CompileRun( 900 CompileRun(
900 "function A(s) { this.s = s; }\n" 901 "function A(s) { this.s = s; }\n"
901 "function B(x) { this.x = x; }\n" 902 "function B(x) { this.x = x; }\n"
902 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" 903 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n"
903 "var b = new B(a);"); 904 "var b = new B(a);");
904 const v8::HeapSnapshot* snapshot = 905 const v8::HeapSnapshot* snapshot =
905 heap_profiler->TakeHeapSnapshot(v8_str("json")); 906 heap_profiler->TakeHeapSnapshot(v8_str("json"));
(...skipping 10 matching lines...) Expand all
916 OneByteResource* json_res = new OneByteResource(json); 917 OneByteResource* json_res = new OneByteResource(json);
917 v8::Local<v8::String> json_string = 918 v8::Local<v8::String> json_string =
918 v8::String::NewExternal(env->GetIsolate(), json_res); 919 v8::String::NewExternal(env->GetIsolate(), json_res);
919 env->Global()->Set(v8_str("json_snapshot"), json_string); 920 env->Global()->Set(v8_str("json_snapshot"), json_string);
920 v8::Local<v8::Value> snapshot_parse_result = CompileRun( 921 v8::Local<v8::Value> snapshot_parse_result = CompileRun(
921 "var parsed = JSON.parse(json_snapshot); true;"); 922 "var parsed = JSON.parse(json_snapshot); true;");
922 CHECK(!snapshot_parse_result.IsEmpty()); 923 CHECK(!snapshot_parse_result.IsEmpty());
923 924
924 // Verify that snapshot object has required fields. 925 // Verify that snapshot object has required fields.
925 v8::Local<v8::Object> parsed_snapshot = 926 v8::Local<v8::Object> parsed_snapshot =
926 env->Global()->Get(v8_str("parsed"))->ToObject(); 927 env->Global()->Get(v8_str("parsed"))->ToObject(isolate);
927 CHECK(parsed_snapshot->Has(v8_str("snapshot"))); 928 CHECK(parsed_snapshot->Has(v8_str("snapshot")));
928 CHECK(parsed_snapshot->Has(v8_str("nodes"))); 929 CHECK(parsed_snapshot->Has(v8_str("nodes")));
929 CHECK(parsed_snapshot->Has(v8_str("edges"))); 930 CHECK(parsed_snapshot->Has(v8_str("edges")));
930 CHECK(parsed_snapshot->Has(v8_str("strings"))); 931 CHECK(parsed_snapshot->Has(v8_str("strings")));
931 932
932 // Get node and edge "member" offsets. 933 // Get node and edge "member" offsets.
933 v8::Local<v8::Value> meta_analysis_result = CompileRun( 934 v8::Local<v8::Value> meta_analysis_result = CompileRun(
934 "var meta = parsed.snapshot.meta;\n" 935 "var meta = parsed.snapshot.meta;\n"
935 "var edge_count_offset = meta.node_fields.indexOf('edge_count');\n" 936 "var edge_count_offset = meta.node_fields.indexOf('edge_count');\n"
936 "var node_fields_count = meta.node_fields.length;\n" 937 "var node_fields_count = meta.node_fields.length;\n"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 v8::Local<v8::Value> string_obj_pos_val = CompileRun( 973 v8::Local<v8::Value> string_obj_pos_val = CompileRun(
973 "GetChildPosByProperty(\n" 974 "GetChildPosByProperty(\n"
974 " GetChildPosByProperty(\n" 975 " GetChildPosByProperty(\n"
975 " GetChildPosByProperty(" 976 " GetChildPosByProperty("
976 " parsed.edges[edge_fields_count + edge_to_node_offset]," 977 " parsed.edges[edge_fields_count + edge_to_node_offset],"
977 " \"b\", property_type),\n" 978 " \"b\", property_type),\n"
978 " \"x\", property_type)," 979 " \"x\", property_type),"
979 " \"s\", property_type)"); 980 " \"s\", property_type)");
980 CHECK(!string_obj_pos_val.IsEmpty()); 981 CHECK(!string_obj_pos_val.IsEmpty());
981 int string_obj_pos = 982 int string_obj_pos =
982 static_cast<int>(string_obj_pos_val->ToNumber()->Value()); 983 static_cast<int>(string_obj_pos_val->ToNumber(isolate)->Value());
983 v8::Local<v8::Object> nodes_array = 984 v8::Local<v8::Object> nodes_array =
984 parsed_snapshot->Get(v8_str("nodes"))->ToObject(); 985 parsed_snapshot->Get(v8_str("nodes"))->ToObject(isolate);
985 int string_index = static_cast<int>( 986 int string_index = static_cast<int>(
986 nodes_array->Get(string_obj_pos + 1)->ToNumber()->Value()); 987 nodes_array->Get(string_obj_pos + 1)->ToNumber(isolate)->Value());
987 CHECK_GT(string_index, 0); 988 CHECK_GT(string_index, 0);
988 v8::Local<v8::Object> strings_array = 989 v8::Local<v8::Object> strings_array =
989 parsed_snapshot->Get(v8_str("strings"))->ToObject(); 990 parsed_snapshot->Get(v8_str("strings"))->ToObject(isolate);
990 v8::Local<v8::String> string = strings_array->Get(string_index)->ToString(); 991 v8::Local<v8::String> string =
992 strings_array->Get(string_index)->ToString(isolate);
991 v8::Local<v8::String> ref_string = 993 v8::Local<v8::String> ref_string =
992 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(); 994 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(isolate);
993 #undef STRING_LITERAL_FOR_TEST 995 #undef STRING_LITERAL_FOR_TEST
994 CHECK_EQ(*v8::String::Utf8Value(ref_string), 996 CHECK_EQ(*v8::String::Utf8Value(ref_string),
995 *v8::String::Utf8Value(string)); 997 *v8::String::Utf8Value(string));
996 } 998 }
997 999
998 1000
999 TEST(HeapSnapshotJSONSerializationAborting) { 1001 TEST(HeapSnapshotJSONSerializationAborting) {
1000 LocalContext env; 1002 LocalContext env;
1001 v8::HandleScope scope(env->GetIsolate()); 1003 v8::HandleScope scope(env->GetIsolate());
1002 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1004 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); 1944 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter");
1943 CHECK_EQ(NULL, func); 1945 CHECK_EQ(NULL, func);
1944 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter"); 1946 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter");
1945 CHECK_NE(NULL, func); 1947 CHECK_NE(NULL, func);
1946 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter"); 1948 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter");
1947 CHECK_EQ(NULL, func); 1949 CHECK_EQ(NULL, func);
1948 } 1950 }
1949 1951
1950 1952
1951 TEST(HiddenPropertiesFastCase) { 1953 TEST(HiddenPropertiesFastCase) {
1954 v8::Isolate* isolate = CcTest::isolate();
1952 LocalContext env; 1955 LocalContext env;
1953 v8::HandleScope scope(env->GetIsolate()); 1956 v8::HandleScope scope(isolate);
1954 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1957 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
1955 1958
1956 CompileRun( 1959 CompileRun(
1957 "function C(x) { this.a = this; this.b = x; }\n" 1960 "function C(x) { this.a = this; this.b = x; }\n"
1958 "c = new C(2012);\n"); 1961 "c = new C(2012);\n");
1959 const v8::HeapSnapshot* snapshot = 1962 const v8::HeapSnapshot* snapshot =
1960 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1")); 1963 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1"));
1961 CHECK(ValidateSnapshot(snapshot)); 1964 CHECK(ValidateSnapshot(snapshot));
1962 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1965 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1963 const v8::HeapGraphNode* c = 1966 const v8::HeapGraphNode* c =
1964 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); 1967 GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
1965 CHECK_NE(NULL, c); 1968 CHECK_NE(NULL, c);
1966 const v8::HeapGraphNode* hidden_props = 1969 const v8::HeapGraphNode* hidden_props =
1967 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties"); 1970 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties");
1968 CHECK_EQ(NULL, hidden_props); 1971 CHECK_EQ(NULL, hidden_props);
1969 1972
1970 v8::Handle<v8::Value> cHandle = 1973 v8::Handle<v8::Value> cHandle =
1971 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c")); 1974 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c"));
1972 CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); 1975 CHECK(!cHandle.IsEmpty() && cHandle->IsObject());
1973 cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val")); 1976 cHandle->ToObject(isolate)->SetHiddenValue(v8_str("key"), v8_str("val"));
1974 1977
1975 snapshot = heap_profiler->TakeHeapSnapshot( 1978 snapshot = heap_profiler->TakeHeapSnapshot(
1976 v8_str("HiddenPropertiesFastCase2")); 1979 v8_str("HiddenPropertiesFastCase2"));
1977 CHECK(ValidateSnapshot(snapshot)); 1980 CHECK(ValidateSnapshot(snapshot));
1978 global = GetGlobalObject(snapshot); 1981 global = GetGlobalObject(snapshot);
1979 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); 1982 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
1980 CHECK_NE(NULL, c); 1983 CHECK_NE(NULL, c);
1981 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal, 1984 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal,
1982 "hidden_properties"); 1985 "hidden_properties");
1983 CHECK_NE(NULL, hidden_props); 1986 CHECK_NE(NULL, hidden_props);
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2794 map.AddRange(ToAddress(0x180), 0x80, 6U); 2797 map.AddRange(ToAddress(0x180), 0x80, 6U);
2795 map.AddRange(ToAddress(0x180), 0x80, 7U); 2798 map.AddRange(ToAddress(0x180), 0x80, 7U);
2796 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); 2799 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180)));
2797 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); 2800 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
2798 CHECK_EQ(3, static_cast<int>(map.size())); 2801 CHECK_EQ(3, static_cast<int>(map.size()));
2799 2802
2800 map.Clear(); 2803 map.Clear();
2801 CHECK_EQ(0, static_cast<int>(map.size())); 2804 CHECK_EQ(0, static_cast<int>(map.size()));
2802 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); 2805 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400)));
2803 } 2806 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698