Chromium Code Reviews| 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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 return; | 1022 return; |
| 1023 } | 1023 } |
| 1024 CHECK(HEAP->old_pointer_space()->Contains(clone->address())); | 1024 CHECK(HEAP->old_pointer_space()->Contains(clone->address())); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 | 1027 |
| 1028 TEST(TestCodeFlushing) { | 1028 TEST(TestCodeFlushing) { |
| 1029 // If we do not flush code this test is invalid. | 1029 // If we do not flush code this test is invalid. |
| 1030 if (!FLAG_flush_code) return; | 1030 if (!FLAG_flush_code) return; |
| 1031 i::FLAG_allow_natives_syntax = true; | 1031 i::FLAG_allow_natives_syntax = true; |
| 1032 i::FLAG_optimize_for_size = false; | |
| 1032 CcTest::InitializeVM(); | 1033 CcTest::InitializeVM(); |
| 1033 Isolate* isolate = Isolate::Current(); | 1034 Isolate* isolate = Isolate::Current(); |
| 1034 Factory* factory = isolate->factory(); | 1035 Factory* factory = isolate->factory(); |
| 1035 v8::HandleScope scope(CcTest::isolate()); | 1036 v8::HandleScope scope(CcTest::isolate()); |
| 1036 const char* source = "function foo() {" | 1037 const char* source = "function foo() {" |
| 1037 " var x = 42;" | 1038 " var x = 42;" |
| 1038 " var y = 42;" | 1039 " var y = 42;" |
| 1039 " var z = x + y;" | 1040 " var z = x + y;" |
| 1040 "};" | 1041 "};" |
| 1041 "foo()"; | 1042 "foo()"; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1067 // foo should no longer be in the compilation cache | 1068 // foo should no longer be in the compilation cache |
| 1068 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); | 1069 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); |
| 1069 CHECK(!function->is_compiled() || function->IsOptimized()); | 1070 CHECK(!function->is_compiled() || function->IsOptimized()); |
| 1070 // Call foo to get it recompiled. | 1071 // Call foo to get it recompiled. |
| 1071 CompileRun("foo()"); | 1072 CompileRun("foo()"); |
| 1072 CHECK(function->shared()->is_compiled()); | 1073 CHECK(function->shared()->is_compiled()); |
| 1073 CHECK(function->is_compiled()); | 1074 CHECK(function->is_compiled()); |
| 1074 } | 1075 } |
| 1075 | 1076 |
| 1076 | 1077 |
| 1078 TEST(TestCodeFlushingPreAged) { | |
| 1079 // If we do not flush code this test is invalid. | |
| 1080 if (!FLAG_flush_code) return; | |
| 1081 i::FLAG_allow_natives_syntax = true; | |
| 1082 i::FLAG_optimize_for_size = true; | |
| 1083 CcTest::InitializeVM(); | |
| 1084 Isolate* isolate = Isolate::Current(); | |
| 1085 Factory* factory = isolate->factory(); | |
| 1086 v8::HandleScope scope(CcTest::isolate()); | |
| 1087 const char* source = "function foo() {" | |
| 1088 " var x = 42;" | |
| 1089 " var y = 42;" | |
| 1090 " var z = x + y;" | |
| 1091 "};" | |
| 1092 "foo()"; | |
| 1093 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); | |
| 1094 | |
| 1095 // Compile foo, but don't run it. | |
| 1096 { v8::HandleScope scope(CcTest::isolate()); | |
| 1097 CompileRun(source); | |
| 1098 } | |
|
rmcilroy
2013/09/23 12:58:34
I would like to test the immediate GCing of code t
| |
| 1099 | |
| 1100 // Check function is compiled. | |
| 1101 Object* func_value = Isolate::Current()->context()->global_object()-> | |
| 1102 GetProperty(*foo_name)->ToObjectChecked(); | |
| 1103 CHECK(func_value->IsJSFunction()); | |
| 1104 Handle<JSFunction> function(JSFunction::cast(func_value)); | |
| 1105 CHECK(function->shared()->is_compiled()); | |
| 1106 | |
| 1107 // The code has been run so will survive at least one GC. | |
| 1108 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 1109 CHECK(function->shared()->is_compiled()); | |
| 1110 | |
| 1111 // The code was only run once, so it should be pre-aged and collected on the | |
| 1112 // next GC. | |
| 1113 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 1114 CHECK(!function->shared()->is_compiled()); | |
| 1115 | |
| 1116 // Execute the function again twice, and ensure it is reset to the young age. | |
| 1117 { v8::HandleScope scope(CcTest::isolate()); | |
| 1118 CompileRun("foo();" | |
| 1119 "foo();"); | |
| 1120 } | |
| 1121 | |
| 1122 // The code will survive at least two GC now that it is young again. | |
| 1123 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 1124 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 1125 CHECK(function->shared()->is_compiled()); | |
| 1126 | |
| 1127 // Simulate several GCs that use full marking. | |
| 1128 const int kAgingThreshold = 6; | |
| 1129 for (int i = 0; i < kAgingThreshold; i++) { | |
| 1130 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 1131 } | |
| 1132 | |
| 1133 // foo should no longer be in the compilation cache | |
| 1134 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); | |
| 1135 CHECK(!function->is_compiled() || function->IsOptimized()); | |
| 1136 // Call foo to get it recompiled. | |
| 1137 CompileRun("foo()"); | |
| 1138 CHECK(function->shared()->is_compiled()); | |
| 1139 CHECK(function->is_compiled()); | |
| 1140 } | |
| 1141 | |
| 1142 | |
| 1077 TEST(TestCodeFlushingIncremental) { | 1143 TEST(TestCodeFlushingIncremental) { |
| 1078 // If we do not flush code this test is invalid. | 1144 // If we do not flush code this test is invalid. |
| 1079 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1145 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
| 1080 i::FLAG_allow_natives_syntax = true; | 1146 i::FLAG_allow_natives_syntax = true; |
| 1147 i::FLAG_optimize_for_size = false; | |
| 1081 CcTest::InitializeVM(); | 1148 CcTest::InitializeVM(); |
| 1082 Isolate* isolate = Isolate::Current(); | 1149 Isolate* isolate = Isolate::Current(); |
| 1083 Factory* factory = isolate->factory(); | 1150 Factory* factory = isolate->factory(); |
| 1084 v8::HandleScope scope(CcTest::isolate()); | 1151 v8::HandleScope scope(CcTest::isolate()); |
| 1085 const char* source = "function foo() {" | 1152 const char* source = "function foo() {" |
| 1086 " var x = 42;" | 1153 " var x = 42;" |
| 1087 " var y = 42;" | 1154 " var y = 42;" |
| 1088 " var z = x + y;" | 1155 " var z = x + y;" |
| 1089 "};" | 1156 "};" |
| 1090 "foo()"; | 1157 "foo()"; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1139 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1206 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1140 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); | 1207 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); |
| 1141 CHECK(function->is_compiled() || !function->IsOptimized()); | 1208 CHECK(function->is_compiled() || !function->IsOptimized()); |
| 1142 } | 1209 } |
| 1143 | 1210 |
| 1144 | 1211 |
| 1145 TEST(TestCodeFlushingIncrementalScavenge) { | 1212 TEST(TestCodeFlushingIncrementalScavenge) { |
| 1146 // If we do not flush code this test is invalid. | 1213 // If we do not flush code this test is invalid. |
| 1147 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1214 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
| 1148 i::FLAG_allow_natives_syntax = true; | 1215 i::FLAG_allow_natives_syntax = true; |
| 1216 i::FLAG_optimize_for_size = false; | |
| 1149 CcTest::InitializeVM(); | 1217 CcTest::InitializeVM(); |
| 1150 Isolate* isolate = Isolate::Current(); | 1218 Isolate* isolate = Isolate::Current(); |
| 1151 Factory* factory = isolate->factory(); | 1219 Factory* factory = isolate->factory(); |
| 1152 v8::HandleScope scope(CcTest::isolate()); | 1220 v8::HandleScope scope(CcTest::isolate()); |
| 1153 const char* source = "var foo = function() {" | 1221 const char* source = "var foo = function() {" |
| 1154 " var x = 42;" | 1222 " var x = 42;" |
| 1155 " var y = 42;" | 1223 " var y = 42;" |
| 1156 " var z = x + y;" | 1224 " var z = x + y;" |
| 1157 "};" | 1225 "};" |
| 1158 "foo();" | 1226 "foo();" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1207 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1275 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1208 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); | 1276 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); |
| 1209 CHECK(!function->is_compiled() || function->IsOptimized()); | 1277 CHECK(!function->is_compiled() || function->IsOptimized()); |
| 1210 } | 1278 } |
| 1211 | 1279 |
| 1212 | 1280 |
| 1213 TEST(TestCodeFlushingIncrementalAbort) { | 1281 TEST(TestCodeFlushingIncrementalAbort) { |
| 1214 // If we do not flush code this test is invalid. | 1282 // If we do not flush code this test is invalid. |
| 1215 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1283 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
| 1216 i::FLAG_allow_natives_syntax = true; | 1284 i::FLAG_allow_natives_syntax = true; |
| 1285 i::FLAG_optimize_for_size = false; | |
| 1217 CcTest::InitializeVM(); | 1286 CcTest::InitializeVM(); |
| 1218 Isolate* isolate = Isolate::Current(); | 1287 Isolate* isolate = Isolate::Current(); |
| 1219 Factory* factory = isolate->factory(); | 1288 Factory* factory = isolate->factory(); |
| 1220 Heap* heap = isolate->heap(); | 1289 Heap* heap = isolate->heap(); |
| 1221 v8::HandleScope scope(CcTest::isolate()); | 1290 v8::HandleScope scope(CcTest::isolate()); |
| 1222 const char* source = "function foo() {" | 1291 const char* source = "function foo() {" |
| 1223 " var x = 42;" | 1292 " var x = 42;" |
| 1224 " var y = 42;" | 1293 " var y = 42;" |
| 1225 " var z = x + y;" | 1294 " var z = x + y;" |
| 1226 "};" | 1295 "};" |
| (...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3436 " var a = new Array(n);" | 3505 " var a = new Array(n);" |
| 3437 " for (var i = 0; i < n; i += 100) a[i] = i;" | 3506 " for (var i = 0; i < n; i += 100) a[i] = i;" |
| 3438 "};" | 3507 "};" |
| 3439 "f(10 * 1024 * 1024);"); | 3508 "f(10 * 1024 * 1024);"); |
| 3440 IncrementalMarking* marking = HEAP->incremental_marking(); | 3509 IncrementalMarking* marking = HEAP->incremental_marking(); |
| 3441 if (marking->IsStopped()) marking->Start(); | 3510 if (marking->IsStopped()) marking->Start(); |
| 3442 // This big step should be sufficient to mark the whole array. | 3511 // This big step should be sufficient to mark the whole array. |
| 3443 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 3512 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 3444 ASSERT(marking->IsComplete()); | 3513 ASSERT(marking->IsComplete()); |
| 3445 } | 3514 } |
| OLD | NEW |