FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node/src/compile_cache.h at main · MoLow/node · GitHub
MoLow
/
node
Public
forked from
nodejs/node
Notifications
You must be signed in to change notification settings
Fork
2
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
node
/
src
/
compile_cache.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
117 lines (94 loc) · 3.63 KB
Breadcrumbs
node
/
src
/
compile_cache.h
Copy path
File metadata and controls
117 lines (94 loc) · 3.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#
ifndef
SRC_COMPILE_CACHE_H_
#
define
SRC_COMPILE_CACHE_H_
#
if
defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#
include
<
cinttypes
>
#
include
<
memory
>
#
include
<
string
>
#
include
<
string_view
>
#
include
<
unordered_map
>
#
include
"
v8.h
"
namespace
node
{
class
Environment
;
#
define
CACHED_CODE_TYPES
(
V
) \
V
(
kCommonJS
,
0
) \
V
(
kESM
,
1
) \
V
(
kStrippedTypeScript
,
2
)
enum
class
CachedCodeType
:
uint8_t
{
#
define
V
(
type, value
) type = value,
CACHED_CODE_TYPES
(V)
#
undef
V
};
struct
CompileCacheEntry
{
std::unique_ptr<v8::ScriptCompiler::CachedData> cache{
nullptr
};
uint32_t
cache_key;
uint32_t
code_hash;
uint32_t
code_size;
std::string cache_filename;
std::string source_filename;
CachedCodeType type;
bool
refreshed =
false
;
bool
persisted =
false
;
//
Copy the cache into a new store for V8 to consume. Caller takes
//
ownership.
v8::ScriptCompiler::CachedData*
CopyCache
()
const
;
const
char
*
type_name
()
const
;
};
#
define
COMPILE_CACHE_STATUS
(
V
) \
V
(
FAILED
)
/*
Failed to enable the cache
*/
\
V
(
ENABLED
)
/*
Was not enabled before, and now enabled.
*/
\
V
(
ALREADY_ENABLED
)
/*
Was already enabled.
*/
\
V
(
DISABLED
)
/*
Has been disabled by NODE_DISABLE_COMPILE_CACHE.
*/
enum
class
CompileCacheEnableStatus
:
uint8_t
{
#
define
V
(
status
) status,
COMPILE_CACHE_STATUS
(V)
#
undef
V
};
struct
CompileCacheEnableResult
{
CompileCacheEnableStatus status;
std::string cache_directory;
std::string message;
//
Set in case of failure.
};
enum
class
EnableOption
:
uint8_t
{
DEFAULT
,
PORTABLE
};
class
CompileCacheHandler
{
public:
explicit
CompileCacheHandler
(Environment* env);
CompileCacheEnableResult
Enable
(Environment* env,
const
std::string& dir,
EnableOption option = EnableOption::
DEFAULT
);
void
Persist
();
CompileCacheEntry*
GetOrInsert
(v8::Local<v8::String> code,
v8::Local<v8::String> filename,
CachedCodeType type);
void
MaybeSave
(CompileCacheEntry* entry,
v8::Local<v8::Function> func,
bool
rejected);
void
MaybeSave
(CompileCacheEntry* entry,
v8::Local<v8::Module> mod,
bool
rejected);
void
MaybeSave
(CompileCacheEntry* entry, std::string_view transpiled);
std::string_view
cache_dir
() {
return
compile_cache_dir_; }
private:
void
ReadCacheFile
(CompileCacheEntry* entry);
template
<
typename
T>
void
MaybeSaveImpl
(CompileCacheEntry* entry,
v8::Local<T> func_or_mod,
bool
rejected);
template
<
typename
... Args>
inline
void
Debug
(
const
char
* format, Args&&... args)
const
;
static
constexpr
size_t
kMagicNumberOffset
=
0
;
static
constexpr
size_t
kCodeSizeOffset
=
1
;
static
constexpr
size_t
kCacheSizeOffset
=
2
;
static
constexpr
size_t
kCodeHashOffset
=
3
;
static
constexpr
size_t
kCacheHashOffset
=
4
;
static
constexpr
size_t
kHeaderCount
=
5
;
v8::Isolate* isolate_ =
nullptr
;
bool
is_debug_ =
false
;
std::string compile_cache_dir_;
std::string normalized_compile_cache_dir_;
EnableOption portable_ = EnableOption::
DEFAULT
;
std::unordered_map<
uint32_t
, std::unique_ptr<CompileCacheEntry>>
compiler_cache_store_;
};
}
//
namespace node
#
endif
//
defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#
endif
//
SRC_COMPILE_CACHE_H_
Back
|
FazBrowse Home
|
New Git URL