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

Unified Diff: src/snapshot/natives.h

Issue 2807023003: [snapshot] encode resource before serializing. (Closed)
Patch Set: fix Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/snapshot/deserializer.cc ('k') | src/snapshot/natives-common.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/snapshot/natives.h
diff --git a/src/snapshot/natives.h b/src/snapshot/natives.h
index 0f09e207dc4db5f1fe3591f15fb734d2c00fd469..79f7db39227bfd7fc309155b19623eacbdf6c074 100644
--- a/src/snapshot/natives.h
+++ b/src/snapshot/natives.h
@@ -5,6 +5,7 @@
#ifndef V8_SNAPSHOT_NATIVES_H_
#define V8_SNAPSHOT_NATIVES_H_
+#include "include/v8.h"
#include "src/objects.h"
#include "src/vector.h"
@@ -46,10 +47,6 @@ class V8_EXPORT_PRIVATE NativesCollection {
static Vector<const char> GetScriptSource(int index);
static Vector<const char> GetScriptName(int index);
static Vector<const char> GetScriptsSource();
-
- // The following methods are implemented in natives-common.cc:
-
- static FixedArray* GetSourceCache(Heap* heap);
};
typedef NativesCollection<CORE> Natives;
@@ -64,6 +61,37 @@ void ReadNatives();
void DisposeNatives();
#endif
+class NativesExternalStringResource final
+ : public v8::String::ExternalOneByteStringResource {
+ public:
+ NativesExternalStringResource(NativeType type, int index);
+
+ const char* data() const override { return data_; }
+ size_t length() const override { return length_; }
+
+ v8::String::ExternalOneByteStringResource* EncodeForSerialization() const {
+ DCHECK(type_ == CORE || type_ == EXTRAS);
+ intptr_t val = (index_ << 1) | ((type_ == CORE) ? 0 : 1);
+ val = val << kPointerSizeLog2; // Pointer align.
+ return reinterpret_cast<v8::String::ExternalOneByteStringResource*>(val);
+ }
+
+ // Decode from serialization.
+ static NativesExternalStringResource* DecodeForDeserialization(
+ const v8::String::ExternalOneByteStringResource* encoded) {
+ intptr_t val = reinterpret_cast<intptr_t>(encoded) >> kPointerSizeLog2;
+ NativeType type = (val & 1) ? EXTRAS : CORE;
+ int index = static_cast<int>(val >> 1);
+ return new NativesExternalStringResource(type, index);
+ }
+
+ private:
+ const char* data_;
+ size_t length_;
+ NativeType type_;
+ int index_;
+};
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/snapshot/deserializer.cc ('k') | src/snapshot/natives-common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698