OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/log.h" | 5 #include "src/log.h" |
6 | 6 |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <memory> | 8 #include <memory> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1322 } | 1322 } |
1323 } | 1323 } |
1324 | 1324 |
1325 | 1325 |
1326 // This function can be called when Log's mutex is acquired, | 1326 // This function can be called when Log's mutex is acquired, |
1327 // either from main or Profiler's thread. | 1327 // either from main or Profiler's thread. |
1328 void Logger::LogFailure() { | 1328 void Logger::LogFailure() { |
1329 StopProfiler(); | 1329 StopProfiler(); |
1330 } | 1330 } |
1331 | 1331 |
1332 static void AddFunctionAndCode(SharedFunctionInfo* sfi, | |
1333 AbstractCode* code_object, | |
1334 Handle<SharedFunctionInfo>* sfis, | |
1335 Handle<AbstractCode>* code_objects, int offset) { | |
1336 if (sfis != NULL) { | |
1337 sfis[offset] = Handle<SharedFunctionInfo>(sfi); | |
1338 } | |
1339 if (code_objects != NULL) { | |
1340 code_objects[offset] = Handle<AbstractCode>(code_object); | |
1341 } | |
1342 } | |
1332 | 1343 |
1333 class EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor { | 1344 class EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor { |
1334 public: | 1345 public: |
1335 EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis, | 1346 EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis, |
1336 Handle<AbstractCode>* code_objects, | 1347 Handle<AbstractCode>* code_objects, |
1337 int* count) | 1348 int* count) |
1338 : sfis_(sfis), code_objects_(code_objects), count_(count) {} | 1349 : sfis_(sfis), code_objects_(code_objects), count_(count) {} |
1339 | 1350 |
1340 virtual void EnterContext(Context* context) {} | 1351 virtual void EnterContext(Context* context) {} |
1341 virtual void LeaveContext(Context* context) {} | 1352 virtual void LeaveContext(Context* context) {} |
1342 | 1353 |
1343 virtual void VisitFunction(JSFunction* function) { | 1354 virtual void VisitFunction(JSFunction* function) { |
1344 SharedFunctionInfo* sfi = SharedFunctionInfo::cast(function->shared()); | 1355 SharedFunctionInfo* sfi = SharedFunctionInfo::cast(function->shared()); |
1345 Object* maybe_script = sfi->script(); | 1356 Object* maybe_script = sfi->script(); |
1346 if (maybe_script->IsScript() | 1357 if (maybe_script->IsScript() |
1347 && !Script::cast(maybe_script)->HasValidSource()) return; | 1358 && !Script::cast(maybe_script)->HasValidSource()) return; |
1348 if (sfis_ != NULL) { | 1359 |
1349 sfis_[*count_] = Handle<SharedFunctionInfo>(sfi); | 1360 DCHECK(function->abstract_code()->kind() == |
1350 } | 1361 AbstractCode::OPTIMIZED_FUNCTION); |
1351 if (code_objects_ != NULL) { | 1362 AddFunctionAndCode(sfi, function->abstract_code(), sfis_, code_objects_, |
1352 DCHECK(function->abstract_code()->kind() == | 1363 *count_); |
1353 AbstractCode::OPTIMIZED_FUNCTION); | |
1354 code_objects_[*count_] = Handle<AbstractCode>(function->abstract_code()); | |
1355 } | |
1356 *count_ = *count_ + 1; | 1364 *count_ = *count_ + 1; |
1357 } | 1365 } |
1358 | 1366 |
1359 private: | 1367 private: |
1360 Handle<SharedFunctionInfo>* sfis_; | 1368 Handle<SharedFunctionInfo>* sfis_; |
1361 Handle<AbstractCode>* code_objects_; | 1369 Handle<AbstractCode>* code_objects_; |
1362 int* count_; | 1370 int* count_; |
1363 }; | 1371 }; |
1364 | 1372 |
1365 static int EnumerateCompiledFunctions(Heap* heap, | 1373 static int EnumerateCompiledFunctions(Heap* heap, |
1366 Handle<SharedFunctionInfo>* sfis, | 1374 Handle<SharedFunctionInfo>* sfis, |
1367 Handle<AbstractCode>* code_objects) { | 1375 Handle<AbstractCode>* code_objects) { |
1368 HeapIterator iterator(heap); | 1376 HeapIterator iterator(heap); |
1369 DisallowHeapAllocation no_gc; | 1377 DisallowHeapAllocation no_gc; |
1370 int compiled_funcs_count = 0; | 1378 int compiled_funcs_count = 0; |
1371 | 1379 |
1372 // Iterate the heap to find shared function info objects and record | 1380 // Iterate the heap to find shared function info objects and record |
1373 // the unoptimized code for them. | 1381 // the unoptimized code for them. |
1374 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 1382 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
1375 if (!obj->IsSharedFunctionInfo()) continue; | 1383 if (!obj->IsSharedFunctionInfo()) continue; |
1376 SharedFunctionInfo* sfi = SharedFunctionInfo::cast(obj); | 1384 SharedFunctionInfo* sfi = SharedFunctionInfo::cast(obj); |
1377 if (sfi->is_compiled() | 1385 if (sfi->is_compiled() |
1378 && (!sfi->script()->IsScript() | 1386 && (!sfi->script()->IsScript() |
1379 || Script::cast(sfi->script())->HasValidSource())) { | 1387 || Script::cast(sfi->script())->HasValidSource())) { |
1380 if (sfis != NULL) { | 1388 // In some cases, an SFI might have (and have executing!) both bytecode |
1381 sfis[compiled_funcs_count] = Handle<SharedFunctionInfo>(sfi); | 1389 // and baseline code, so check for both and add them both if needed. |
1390 if (sfi->HasBytecodeArray()) { | |
1391 AddFunctionAndCode(sfi, AbstractCode::cast(sfi->bytecode_array()), sfis, | |
1392 code_objects, compiled_funcs_count); | |
1393 ++compiled_funcs_count; | |
1382 } | 1394 } |
1383 if (code_objects != NULL) { | 1395 |
1384 code_objects[compiled_funcs_count] = | 1396 if (!sfi->IsInterpreted()) { |
rmcilroy
2017/01/03 12:42:08
We might want to replace this with HasBaselineCode
| |
1385 Handle<AbstractCode>(sfi->abstract_code()); | 1397 AddFunctionAndCode(sfi, AbstractCode::cast(sfi->code()), sfis, |
1398 code_objects, compiled_funcs_count); | |
1399 ++compiled_funcs_count; | |
1386 } | 1400 } |
1387 ++compiled_funcs_count; | |
1388 } | 1401 } |
1389 } | 1402 } |
1390 | 1403 |
1391 // Iterate all optimized functions in all contexts. | 1404 // Iterate all optimized functions in all contexts. |
1392 EnumerateOptimizedFunctionsVisitor visitor(sfis, | 1405 EnumerateOptimizedFunctionsVisitor visitor(sfis, |
1393 code_objects, | 1406 code_objects, |
1394 &compiled_funcs_count); | 1407 &compiled_funcs_count); |
1395 Deoptimizer::VisitAllOptimizedFunctions(heap->isolate(), &visitor); | 1408 Deoptimizer::VisitAllOptimizedFunctions(heap->isolate(), &visitor); |
1396 | 1409 |
1397 return compiled_funcs_count; | 1410 return compiled_funcs_count; |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1780 | 1793 |
1781 if (profiler_listener_.get() != nullptr) { | 1794 if (profiler_listener_.get() != nullptr) { |
1782 removeCodeEventListener(profiler_listener_.get()); | 1795 removeCodeEventListener(profiler_listener_.get()); |
1783 } | 1796 } |
1784 | 1797 |
1785 return log_->Close(); | 1798 return log_->Close(); |
1786 } | 1799 } |
1787 | 1800 |
1788 } // namespace internal | 1801 } // namespace internal |
1789 } // namespace v8 | 1802 } // namespace v8 |
OLD | NEW |