OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "compilation-cache.h" | 7 #include "compilation-cache.h" |
8 #include "execution.h" | 8 #include "execution.h" |
9 #include "factory.h" | 9 #include "factory.h" |
10 #include "macro-assembler.h" | 10 #include "macro-assembler.h" |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 *function2.location() = NULL; | 1126 *function2.location() = NULL; |
1127 HEAP->CollectGarbage(NEW_SPACE, "test scavenge while marking"); | 1127 HEAP->CollectGarbage(NEW_SPACE, "test scavenge while marking"); |
1128 | 1128 |
1129 // Simulate one final GC to make sure the candidate queue is sane. | 1129 // Simulate one final GC to make sure the candidate queue is sane. |
1130 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1130 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1131 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); | 1131 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); |
1132 CHECK(!function->is_compiled() || function->IsOptimized()); | 1132 CHECK(!function->is_compiled() || function->IsOptimized()); |
1133 } | 1133 } |
1134 | 1134 |
1135 | 1135 |
| 1136 TEST(TestCodeFlushingIncrementalAbort) { |
| 1137 // If we do not flush code this test is invalid. |
| 1138 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
| 1139 i::FLAG_allow_natives_syntax = true; |
| 1140 InitializeVM(); |
| 1141 v8::HandleScope scope; |
| 1142 const char* source = "function foo() {" |
| 1143 " var x = 42;" |
| 1144 " var y = 42;" |
| 1145 " var z = x + y;" |
| 1146 "};" |
| 1147 "foo()"; |
| 1148 Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo"); |
| 1149 |
| 1150 // This compile will add the code to the compilation cache. |
| 1151 { v8::HandleScope scope; |
| 1152 CompileRun(source); |
| 1153 } |
| 1154 |
| 1155 // Check function is compiled. |
| 1156 Object* func_value = Isolate::Current()->context()->global_object()-> |
| 1157 GetProperty(*foo_name)->ToObjectChecked(); |
| 1158 CHECK(func_value->IsJSFunction()); |
| 1159 Handle<JSFunction> function(JSFunction::cast(func_value)); |
| 1160 CHECK(function->shared()->is_compiled()); |
| 1161 |
| 1162 // The code will survive at least two GCs. |
| 1163 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1164 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1165 CHECK(function->shared()->is_compiled()); |
| 1166 |
| 1167 // Bump the code age so that flushing is triggered. |
| 1168 const int kAgingThreshold = 6; |
| 1169 function->shared()->set_code_age(kAgingThreshold); |
| 1170 |
| 1171 // Simulate incremental marking so that the function is enqueued as |
| 1172 // code flushing candidate. |
| 1173 SimulateIncrementalMarking(); |
| 1174 |
| 1175 // Enable the debugger and add a breakpoint while incremental marking |
| 1176 // is running so that incremental marking aborts and code flushing is |
| 1177 // disabled. |
| 1178 int position = 0; |
| 1179 Handle<Object> breakpoint_object(Smi::FromInt(0)); |
| 1180 ISOLATE->debug()->SetBreakPoint(function, breakpoint_object, &position); |
| 1181 ISOLATE->debug()->ClearAllBreakPoints(); |
| 1182 |
| 1183 // Force optimization now that code flushing is disabled. |
| 1184 { v8::HandleScope scope; |
| 1185 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); |
| 1186 } |
| 1187 |
| 1188 // Simulate one final GC to make sure the candidate queue is sane. |
| 1189 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
| 1190 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); |
| 1191 CHECK(function->is_compiled() || !function->IsOptimized()); |
| 1192 } |
| 1193 |
| 1194 |
1136 // Count the number of native contexts in the weak list of native contexts. | 1195 // Count the number of native contexts in the weak list of native contexts. |
1137 int CountNativeContexts() { | 1196 int CountNativeContexts() { |
1138 int count = 0; | 1197 int count = 0; |
1139 Object* object = HEAP->native_contexts_list(); | 1198 Object* object = HEAP->native_contexts_list(); |
1140 while (!object->IsUndefined()) { | 1199 while (!object->IsUndefined()) { |
1141 count++; | 1200 count++; |
1142 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); | 1201 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); |
1143 } | 1202 } |
1144 return count; | 1203 return count; |
1145 } | 1204 } |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2434 Handle<Object> call_function(call); | 2493 Handle<Object> call_function(call); |
2435 | 2494 |
2436 // Now we are ready to mess up the heap. | 2495 // Now we are ready to mess up the heap. |
2437 HEAP->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); | 2496 HEAP->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); |
2438 | 2497 |
2439 // Either heap verification caught the problem already or we go kaboom once | 2498 // Either heap verification caught the problem already or we go kaboom once |
2440 // the CallIC is executed the next time. | 2499 // the CallIC is executed the next time. |
2441 USE(global->SetProperty(*name, *call_function, NONE, kNonStrictMode)); | 2500 USE(global->SetProperty(*name, *call_function, NONE, kNonStrictMode)); |
2442 CompileRun("call();"); | 2501 CompileRun("call();"); |
2443 } | 2502 } |
OLD | NEW |