X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=blobdiff_plain;f=Source%2FJavaScriptCore%2Fruntime%2FCodeCache.h;h=7ab80fe201abd8bfd92e95f460fc367bb3848b78;hp=2befc63ae2b32cacd973114d9c1fc47199932abc;hb=6edb2e853d858b98a291a05353ea6491a53cb5c3;hpb=32d40d7abdaf04407925304067a6cfaf408e4d8c diff --git a/Source/JavaScriptCore/runtime/CodeCache.h b/Source/JavaScriptCore/runtime/CodeCache.h index 2befc63..7ab80fe 100644 --- a/Source/JavaScriptCore/runtime/CodeCache.h +++ b/Source/JavaScriptCore/runtime/CodeCache.h @@ -109,14 +109,60 @@ public: template UnlinkedCodeBlockType* fetchFromDiskImpl(VM& vm, const SourceCodeKey& key) { - const auto* cachedBytecode = key.source().provider().cachedBytecode(); - if (cachedBytecode && cachedBytecode->size()) { - VERBOSE_LOG("Found cached CodeBlock in the SourceProvider"); - UnlinkedCodeBlockType* unlinkedCodeBlock = decodeCodeBlock(vm, key, cachedBytecode->data(), cachedBytecode->size()); - if (unlinkedCodeBlock) - return unlinkedCodeBlock; + { + const auto* cachedBytecode = key.source().provider().cachedBytecode(); + if (cachedBytecode && cachedBytecode->size()) { + VERBOSE_LOG("Found cached CodeBlock in the SourceProvider"); + UnlinkedCodeBlockType* unlinkedCodeBlock = decodeCodeBlock(vm, key, cachedBytecode->data(), cachedBytecode->size()); + if (unlinkedCodeBlock) + return unlinkedCodeBlock; + } } + +#if OS(DARWIN) + const char* cachePath = Options::diskCachePath(); + if (!cachePath) + return nullptr; + + unsigned hash = key.hash(); + char filename[512]; + int count = snprintf(filename, 512, "%s/%u.cache", cachePath, hash); + if (count < 0 || count > 512) + return nullptr; + + int fd = open(filename, O_RDONLY); + if (fd == -1) + return nullptr; + + int rc = flock(fd, LOCK_SH | LOCK_NB); + if (rc) { + close(fd); + return nullptr; + } + + struct stat sb; + int res = fstat(fd, &sb); + size_t size = static_cast(sb.st_size); + if (res || !size) { + close(fd); + return nullptr; + } + + void* buffer = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0); + UnlinkedCodeBlockType* unlinkedCodeBlock = decodeCodeBlock(vm, key, buffer, size); + munmap(buffer, size); + + if (!unlinkedCodeBlock) + return nullptr; + + VERBOSE_LOG("Found cached CodeBlock on disk"); + addCache(key, SourceCodeValue(vm, unlinkedCodeBlock, m_age, true)); + return unlinkedCodeBlock; +#else + UNUSED_PARAM(vm); + UNUSED_PARAM(key); return nullptr; +#endif } template