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

Side by Side Diff: src/d8.cc

Issue 913703002: Fix cctest + unittest to work with an external snapshot. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments. Created 5 years, 10 months 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 | « BUILD.gn ('k') | src/d8.gyp » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 5
6 // Defined when linking against shared lib on Windows. 6 // Defined when linking against shared lib on Windows.
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED)
8 #define V8_SHARED 8 #define V8_SHARED
9 #endif 9 #endif
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "src/base/logging.h" 42 #include "src/base/logging.h"
43 #include "src/base/platform/platform.h" 43 #include "src/base/platform/platform.h"
44 #include "src/base/sys-info.h" 44 #include "src/base/sys-info.h"
45 #include "src/basic-block-profiler.h" 45 #include "src/basic-block-profiler.h"
46 #include "src/d8-debug.h" 46 #include "src/d8-debug.h"
47 #include "src/debug.h" 47 #include "src/debug.h"
48 #include "src/natives.h" 48 #include "src/natives.h"
49 #include "src/v8.h" 49 #include "src/v8.h"
50 #endif // !V8_SHARED 50 #endif // !V8_SHARED
51 51
52 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
53 #include "src/startup-data-util.h"
54 #endif // V8_USE_EXTERNAL_STARTUP_DATA
55
52 #if !defined(_WIN32) && !defined(_WIN64) 56 #if !defined(_WIN32) && !defined(_WIN64)
53 #include <unistd.h> // NOLINT 57 #include <unistd.h> // NOLINT
54 #else 58 #else
55 #include <windows.h> // NOLINT 59 #include <windows.h> // NOLINT
56 #if defined(_MSC_VER) 60 #if defined(_MSC_VER)
57 #include <crtdbg.h> // NOLINT 61 #include <crtdbg.h> // NOLINT
58 #endif // defined(_MSC_VER) 62 #endif // defined(_MSC_VER)
59 #endif // !defined(_WIN32) && !defined(_WIN64) 63 #endif // !defined(_WIN32) && !defined(_WIN64)
60 64
61 #ifndef DCHECK 65 #ifndef DCHECK
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 1542
1539 1543
1540 class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 1544 class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
1541 public: 1545 public:
1542 void* Allocate(size_t) OVERRIDE { return malloc(1); } 1546 void* Allocate(size_t) OVERRIDE { return malloc(1); }
1543 void* AllocateUninitialized(size_t length) OVERRIDE { return malloc(1); } 1547 void* AllocateUninitialized(size_t length) OVERRIDE { return malloc(1); }
1544 void Free(void* p, size_t) OVERRIDE { free(p); } 1548 void Free(void* p, size_t) OVERRIDE { free(p); }
1545 }; 1549 };
1546 1550
1547 1551
1548 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1549 class StartupDataHandler {
1550 public:
1551 StartupDataHandler(const char* exec_path, const char* natives_blob,
1552 const char* snapshot_blob) {
1553 // If we have (at least one) explicitly given blob, use those.
1554 // If not, use the default blob locations next to the d8 binary.
1555 if (natives_blob || snapshot_blob) {
1556 LoadFromFiles(natives_blob, snapshot_blob);
1557 } else {
1558 char* natives;
1559 char* snapshot;
1560 LoadFromFiles(RelativePath(&natives, exec_path, "natives_blob.bin"),
1561 RelativePath(&snapshot, exec_path, "snapshot_blob.bin"));
1562
1563 free(natives);
1564 free(snapshot);
1565 }
1566 }
1567
1568 ~StartupDataHandler() {
1569 delete[] natives_.data;
1570 delete[] snapshot_.data;
1571 }
1572
1573 private:
1574 static char* RelativePath(char** buffer, const char* exec_path,
1575 const char* name) {
1576 DCHECK(exec_path);
1577 const char* last_slash = strrchr(exec_path, '/');
1578 if (last_slash) {
1579 int after_slash = last_slash - exec_path + 1;
1580 int name_length = static_cast<int>(strlen(name));
1581 *buffer =
1582 reinterpret_cast<char*>(calloc(after_slash + name_length + 1, 1));
1583 strncpy(*buffer, exec_path, after_slash);
1584 strncat(*buffer, name, name_length);
1585 } else {
1586 *buffer = strdup(name);
1587 }
1588 return *buffer;
1589 }
1590
1591 void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) {
1592 Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob);
1593 Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob);
1594 }
1595
1596 void Load(const char* blob_file,
1597 v8::StartupData* startup_data,
1598 void (*setter_fn)(v8::StartupData*)) {
1599 startup_data->data = NULL;
1600 startup_data->raw_size = 0;
1601
1602 if (!blob_file)
1603 return;
1604
1605 FILE* file = fopen(blob_file, "rb");
1606 if (!file)
1607 return;
1608
1609 fseek(file, 0, SEEK_END);
1610 startup_data->raw_size = ftell(file);
1611 rewind(file);
1612
1613 startup_data->data = new char[startup_data->raw_size];
1614 int read_size =
1615 static_cast<int>(fread(const_cast<char*>(startup_data->data), 1,
1616 startup_data->raw_size, file));
1617 fclose(file);
1618
1619 if (startup_data->raw_size == read_size) (*setter_fn)(startup_data);
1620 }
1621
1622 v8::StartupData natives_;
1623 v8::StartupData snapshot_;
1624
1625 // Disallow copy & assign.
1626 StartupDataHandler(const StartupDataHandler& other);
1627 void operator=(const StartupDataHandler& other);
1628 };
1629 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1630
1631
1632 int Shell::Main(int argc, char* argv[]) { 1552 int Shell::Main(int argc, char* argv[]) {
1633 #if (defined(_WIN32) || defined(_WIN64)) 1553 #if (defined(_WIN32) || defined(_WIN64))
1634 UINT new_flags = 1554 UINT new_flags =
1635 SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX; 1555 SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX;
1636 UINT existing_flags = SetErrorMode(new_flags); 1556 UINT existing_flags = SetErrorMode(new_flags);
1637 SetErrorMode(existing_flags | new_flags); 1557 SetErrorMode(existing_flags | new_flags);
1638 #if defined(_MSC_VER) 1558 #if defined(_MSC_VER)
1639 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); 1559 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
1640 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); 1560 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
1641 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); 1561 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
1642 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); 1562 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
1643 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); 1563 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
1644 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); 1564 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
1645 _set_error_mode(_OUT_TO_STDERR); 1565 _set_error_mode(_OUT_TO_STDERR);
1646 #endif // defined(_MSC_VER) 1566 #endif // defined(_MSC_VER)
1647 #endif // defined(_WIN32) || defined(_WIN64) 1567 #endif // defined(_WIN32) || defined(_WIN64)
1648 if (!SetOptions(argc, argv)) return 1; 1568 if (!SetOptions(argc, argv)) return 1;
1649 v8::V8::InitializeICU(options.icu_data_file); 1569 v8::V8::InitializeICU(options.icu_data_file);
1650 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); 1570 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
1651 v8::V8::InitializePlatform(platform); 1571 v8::V8::InitializePlatform(platform);
1652 v8::V8::Initialize(); 1572 v8::V8::Initialize();
1653 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 1573 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1654 StartupDataHandler startup_data(argv[0], options.natives_blob, 1574 v8::StartupDataHandler startup_data(argv[0], options.natives_blob,
1655 options.snapshot_blob); 1575 options.snapshot_blob);
1656 #endif 1576 #endif
1657 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); 1577 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg");
1658 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); 1578 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg");
1659 SetFlagsFromString("--redirect-code-traces-to=code.asm"); 1579 SetFlagsFromString("--redirect-code-traces-to=code.asm");
1660 ShellArrayBufferAllocator array_buffer_allocator; 1580 ShellArrayBufferAllocator array_buffer_allocator;
1661 MockArrayBufferAllocator mock_arraybuffer_allocator; 1581 MockArrayBufferAllocator mock_arraybuffer_allocator;
1662 if (options.mock_arraybuffer_allocator) { 1582 if (options.mock_arraybuffer_allocator) {
1663 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator); 1583 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator);
1664 } else { 1584 } else {
1665 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); 1585 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 } 1670 }
1751 1671
1752 } // namespace v8 1672 } // namespace v8
1753 1673
1754 1674
1755 #ifndef GOOGLE3 1675 #ifndef GOOGLE3
1756 int main(int argc, char* argv[]) { 1676 int main(int argc, char* argv[]) {
1757 return v8::Shell::Main(argc, argv); 1677 return v8::Shell::Main(argc, argv);
1758 } 1678 }
1759 #endif 1679 #endif
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/d8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698