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

Side by Side Diff: src/d8.cc

Issue 780333004: Make d8 default to standard location for external snapshots. (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 | « no previous file | no next file » | 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 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 } 1547 }
1548 virtual void Free(void* p, size_t) OVERRIDE { 1548 virtual void Free(void* p, size_t) OVERRIDE {
1549 free(p); 1549 free(p);
1550 } 1550 }
1551 }; 1551 };
1552 1552
1553 1553
1554 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 1554 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1555 class StartupDataHandler { 1555 class StartupDataHandler {
1556 public: 1556 public:
1557 StartupDataHandler(const char* natives_blob, 1557 StartupDataHandler(const char* exec_path, const char* natives_blob,
1558 const char* snapshot_blob) { 1558 const char* snapshot_blob) {
1559 Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob); 1559 // If we have (at least one) explicitly given blob, use those.
1560 Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob); 1560 // If not, use the default blob locations next to the d8 binary.
1561 if (natives_blob || snapshot_blob) {
1562 LoadFromFiles(natives_blob, snapshot_blob);
1563 } else {
1564 char natives[100], snapshot[100];
1565 LoadFromFiles(
1566 RelativePath(natives, exec_path, "natives_blob.bin", sizeof(natives)),
1567 RelativePath(snapshot, exec_path, "snapshot_blob.bin",
1568 sizeof(snapshot)));
1569 }
1561 } 1570 }
1562 1571
1563 ~StartupDataHandler() { 1572 ~StartupDataHandler() {
1564 delete[] natives_.data; 1573 delete[] natives_.data;
1565 delete[] snapshot_.data; 1574 delete[] snapshot_.data;
1566 } 1575 }
1567 1576
1568 private: 1577 private:
1578 static char* RelativePath(char* buffer, const char* exec_path,
1579 const char* name, int buffer_length) {
1580 DCHECK(exec_path);
1581 const char* last_slash = strrchr(exec_path, '/');
1582 if (last_slash) {
1583 int after_slash = last_slash - exec_path + 1;
1584 DCHECK(buffer_length > after_slash);
1585 strncpy(buffer, exec_path, after_slash);
1586 buffer[after_slash] = '\0';
1587 return strncat(buffer, name, buffer_length);
1588 } else {
1589 return strncpy(buffer, name, buffer_length);
1590 }
1591 }
1592
1593 void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) {
1594 Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob);
1595 Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob);
1596 }
1597
1569 void Load(const char* blob_file, 1598 void Load(const char* blob_file,
1570 v8::StartupData* startup_data, 1599 v8::StartupData* startup_data,
1571 void (*setter_fn)(v8::StartupData*)) { 1600 void (*setter_fn)(v8::StartupData*)) {
1572 startup_data->data = NULL; 1601 startup_data->data = NULL;
1573 startup_data->raw_size = 0; 1602 startup_data->raw_size = 0;
1574 1603
1575 if (!blob_file) 1604 if (!blob_file)
1576 return; 1605 return;
1577 1606
1578 FILE* file = fopen(blob_file, "rb"); 1607 FILE* file = fopen(blob_file, "rb");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); 1646 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
1618 _set_error_mode(_OUT_TO_STDERR); 1647 _set_error_mode(_OUT_TO_STDERR);
1619 #endif // defined(_MSC_VER) 1648 #endif // defined(_MSC_VER)
1620 #endif // defined(_WIN32) || defined(_WIN64) 1649 #endif // defined(_WIN32) || defined(_WIN64)
1621 if (!SetOptions(argc, argv)) return 1; 1650 if (!SetOptions(argc, argv)) return 1;
1622 v8::V8::InitializeICU(options.icu_data_file); 1651 v8::V8::InitializeICU(options.icu_data_file);
1623 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); 1652 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
1624 v8::V8::InitializePlatform(platform); 1653 v8::V8::InitializePlatform(platform);
1625 v8::V8::Initialize(); 1654 v8::V8::Initialize();
1626 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 1655 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1627 StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob); 1656 StartupDataHandler startup_data(argv[0], options.natives_blob,
1657 options.snapshot_blob);
1628 #endif 1658 #endif
1629 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); 1659 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg");
1630 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); 1660 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg");
1631 SetFlagsFromString("--redirect-code-traces-to=code.asm"); 1661 SetFlagsFromString("--redirect-code-traces-to=code.asm");
1632 ShellArrayBufferAllocator array_buffer_allocator; 1662 ShellArrayBufferAllocator array_buffer_allocator;
1633 MockArrayBufferAllocator mock_arraybuffer_allocator; 1663 MockArrayBufferAllocator mock_arraybuffer_allocator;
1634 if (options.mock_arraybuffer_allocator) { 1664 if (options.mock_arraybuffer_allocator) {
1635 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator); 1665 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator);
1636 } else { 1666 } else {
1637 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); 1667 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 } 1752 }
1723 1753
1724 } // namespace v8 1754 } // namespace v8
1725 1755
1726 1756
1727 #ifndef GOOGLE3 1757 #ifndef GOOGLE3
1728 int main(int argc, char* argv[]) { 1758 int main(int argc, char* argv[]) {
1729 return v8::Shell::Main(argc, argv); 1759 return v8::Shell::Main(argc, argv);
1730 } 1760 }
1731 #endif 1761 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698