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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 0541d25972bd4288ba48528d271813424adbd025..44a4a81e32c65f7781403b9e148e971e0259360c 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1554,10 +1554,19 @@ class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
class StartupDataHandler {
public:
- StartupDataHandler(const char* natives_blob,
+ StartupDataHandler(const char* exec_path, const char* natives_blob,
const char* snapshot_blob) {
- Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob);
- Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob);
+ // If we have (at least one) explicitly given blob, use those.
+ // If not, use the default blob locations next to the d8 binary.
+ if (natives_blob || snapshot_blob) {
+ LoadFromFiles(natives_blob, snapshot_blob);
+ } else {
+ char natives[100], snapshot[100];
+ LoadFromFiles(
+ RelativePath(natives, exec_path, "natives_blob.bin", sizeof(natives)),
+ RelativePath(snapshot, exec_path, "snapshot_blob.bin",
+ sizeof(snapshot)));
+ }
}
~StartupDataHandler() {
@@ -1566,6 +1575,26 @@ class StartupDataHandler {
}
private:
+ static char* RelativePath(char* buffer, const char* exec_path,
+ const char* name, int buffer_length) {
+ DCHECK(exec_path);
+ const char* last_slash = strrchr(exec_path, '/');
+ if (last_slash) {
+ int after_slash = last_slash - exec_path + 1;
+ DCHECK(buffer_length > after_slash);
+ strncpy(buffer, exec_path, after_slash);
+ buffer[after_slash] = '\0';
+ return strncat(buffer, name, buffer_length);
+ } else {
+ return strncpy(buffer, name, buffer_length);
+ }
+ }
+
+ void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) {
+ Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob);
+ Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob);
+ }
+
void Load(const char* blob_file,
v8::StartupData* startup_data,
void (*setter_fn)(v8::StartupData*)) {
@@ -1624,7 +1653,8 @@ int Shell::Main(int argc, char* argv[]) {
v8::V8::InitializePlatform(platform);
v8::V8::Initialize();
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
- StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob);
+ StartupDataHandler startup_data(argv[0], options.natives_blob,
+ options.snapshot_blob);
#endif
SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg");
SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg");
« 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