| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c95d974 commit ec53d9f
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -446,6 +446,9 @@ | |||
| 446 | 446 | ['v8_enable_pointer_compression == 1', { | |
| 447 | 447 | 'defines': ['V8_COMPRESS_POINTERS'], | |
| 448 | 448 | }], | |
| 449 | + ['v8_enable_pointer_compression == 1 and v8_enable_pointer_compression_shared_cage != 1', { | ||
| 450 | + 'defines': ['V8_COMPRESS_POINTERS_IN_MULTIPLE_CAGES'], | ||
| 451 | + }], | ||
| 449 | 452 | ['v8_enable_pointer_compression_shared_cage == 1', { | |
| 450 | 453 | 'defines': ['V8_COMPRESS_POINTERS_IN_SHARED_CAGE'], | |
| 451 | 454 | }], | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -646,6 +646,12 @@ | |||
| 646 | 646 | default=None, | |
| 647 | 647 | help='[Experimental] Enable V8 pointer compression (limits max heap to 4GB and breaks ABI compatibility)') | |
| 648 | 648 | ||
| 649 | + parser.add_argument('--experimental-pointer-compression-shared-cage', | ||
| 650 | + action='store_true', | ||
| 651 | + dest='pointer_compression_shared_cage', | ||
| 652 | + default=None, | ||
| 653 | + help='[Experimental] Use V8 pointer compression with shared cage (requires --experimental-enable-pointer-compression)') | ||
| 654 | + | ||
| 649 | 655 | parser.add_argument('--v8-options', | |
| 650 | 656 | action='store', | |
| 651 | 657 | dest='v8_options', | |
@@ -1731,7 +1737,10 @@ def configure_v8(o, configs): | |||
| 1731 | 1737 | # Note that enabling pointer compression without enabling sandbox is unsupported by V8, | |
| 1732 | 1738 | # so this can be broken at any time. | |
| 1733 | 1739 | o['variables']['v8_enable_sandbox'] = 0 | |
| 1734 | - o['variables']['v8_enable_pointer_compression_shared_cage'] = 1 if options.enable_pointer_compression else 0 | ||
| 1740 | + # We set v8_enable_pointer_compression_shared_cage to 0 always, even when | ||
| 1741 | + # pointer compression is enabled so that we don't accidentally enable shared | ||
| 1742 | + # cage mode when pointer compression is on. | ||
| 1743 | + o['variables']['v8_enable_pointer_compression_shared_cage'] = 1 if options.pointer_compression_shared_cage else 0 | ||
| 1735 | 1744 | o['variables']['v8_enable_external_code_space'] = 1 if options.enable_pointer_compression else 0 | |
| 1736 | 1745 | o['variables']['v8_enable_31bit_smis_on_64bit_arch'] = 1 if options.enable_pointer_compression else 0 | |
| 1737 | 1746 | o['variables']['v8_enable_extensible_ro_snapshot'] = 0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | #include "debug_utils-inl.h" | |
| 2 | 2 | #include "env-inl.h" | |
| 3 | 3 | #include "node.h" | |
| 4 | + #include "node_internals.h" | ||
| 4 | 5 | #include "node_snapshot_builder.h" | |
| 5 | 6 | ||
| 6 | 7 | using v8::Context; | |
@@ -127,7 +128,7 @@ CommonEnvironmentSetup::CommonEnvironmentSetup( | |||
| 127 | 128 | if (flags & Flags::kIsForSnapshotting) { | |
| 128 | 129 | // The isolate must be registered before the SnapshotCreator initializes the | |
| 129 | 130 | // isolate, so that the memory reducer can be initialized. | |
| 130 | - isolate = impl_->isolate = Isolate::Allocate(); | ||
| 131 | + isolate = impl_->isolate = Isolate::Allocate(GetOrCreateIsolateGroup()); | ||
| 131 | 132 | platform->RegisterIsolate(isolate, loop); | |
| 132 | 133 | ||
| 133 | 134 | impl_->snapshot_creator.emplace(isolate, params); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,7 @@ using v8::Function; | |||
| 37 | 37 | using v8::FunctionCallbackInfo; | |
| 38 | 38 | using v8::HandleScope; | |
| 39 | 39 | using v8::Isolate; | |
| 40 | + using v8::IsolateGroup; | ||
| 40 | 41 | using v8::Just; | |
| 41 | 42 | using v8::JustVoid; | |
| 42 | 43 | using v8::Local; | |
@@ -304,14 +305,26 @@ void SetIsolateUpForNode(v8::Isolate* isolate) { | |||
| 304 | 305 | SetIsolateUpForNode(isolate, settings); | |
| 305 | 306 | } | |
| 306 | 307 | ||
| 308 | + // | ||
| 309 | + IsolateGroup GetOrCreateIsolateGroup() { | ||
| 310 | + // When pointer compression is disabled, we cannot create new groups, | ||
| 311 | + // in which case we'll always return the default. | ||
| 312 | + if (IsolateGroup::CanCreateNewGroups()) { | ||
| 313 | + return IsolateGroup::Create(); | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + return IsolateGroup::GetDefault(); | ||
| 317 | + } | ||
| 318 | + | ||
| 307 | 319 | // TODO(joyeecheung): we may want to expose this, but then we need to be | |
| 308 | 320 | // careful about what we override in the params. | |
| 309 | 321 | Isolate* NewIsolate(Isolate::CreateParams* params, | |
| 310 | 322 | uv_loop_t* event_loop, | |
| 311 | 323 | MultiIsolatePlatform* platform, | |
| 312 | 324 | const SnapshotData* snapshot_data, | |
| 313 | 325 | const IsolateSettings& settings) { | |
| 314 | - Isolate* isolate = Isolate::Allocate(); | ||
| 326 | + IsolateGroup group = GetOrCreateIsolateGroup(); | ||
| 327 | + Isolate* isolate = Isolate::Allocate(group); | ||
| 315 | 328 | if (isolate == nullptr) return nullptr; | |
| 316 | 329 | ||
| 317 | 330 | if (snapshot_data != nullptr) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,6 +56,9 @@ extern uint64_t node_start_time; | |||
| 56 | 56 | // Forward declaration | |
| 57 | 57 | class Environment; | |
| 58 | 58 | ||
| 59 | + static constexpr uint64_t kMaxPointerCompressionHeap = uint64_t{1} | ||
| 60 | + << 32; // 4 GiB | ||
| 61 | + | ||
| 59 | 62 | // Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object. | |
| 60 | 63 | // Sets address and port properties on the info object and returns it. | |
| 61 | 64 | // If |info| is omitted, a new object is returned. | |
@@ -341,6 +344,20 @@ void TraceEnvVar(Environment* env, | |||
| 341 | 344 | v8::Local<v8::String> key); | |
| 342 | 345 | ||
| 343 | 346 | void DefineZlibConstants(v8::Local<v8::Object> target); | |
| 347 | + | ||
| 348 | + // If creating new v8::IsolateGroup instance is supported, this returns a | ||
| 349 | + // new instance. Otherwise, it returns the default instance. | ||
| 350 | + // | ||
| 351 | + // An IsolateGroup is a collection of Isolates that share the same underlying | ||
| 352 | + // pointer cage when pointer compression is enabled. When pointer compression is | ||
| 353 | + // disabled, there is a default IsolateGroup that is used for all isolates, and | ||
| 354 | + // when pointer compression is enabled, all isolates in the app share the | ||
| 355 | + // same pointer cage by default that is limited a maximum of 4GB, not counting | ||
| 356 | + // array buffers and off-heap storage. Multiple IsolateGroups can be used to | ||
| 357 | + // work around the 4GB limit, but each group reserves a range of virtual memory | ||
| 358 | + // addresses, so this should be used with care. | ||
| 359 | + v8::IsolateGroup GetOrCreateIsolateGroup(); | ||
| 360 | + | ||
| 344 | 361 | v8::Isolate* NewIsolate(v8::Isolate::CreateParams* params, | |
| 345 | 362 | uv_loop_t* event_loop, | |
| 346 | 363 | MultiIsolatePlatform* platform, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,7 +127,15 @@ void PerIsolateOptions::HandleMaxOldSpaceSizePercentage( | |||
| 127 | 127 | } | |
| 128 | 128 | ||
| 129 | 129 | // Get available memory in bytes | |
| 130 | + #ifdef V8_COMPRESS_POINTERS | ||
| 131 | + // When pointer compression is enabled, V8 uses a 4 GiB heap limit. | ||
| 132 | + // We'll use the smaller of that or the total system memory as | ||
| 133 | + // reported by uv. | ||
| 134 | + uint64_t total_memory = | ||
| 135 | + std::min(uv_get_total_memory(), kMaxPointerCompressionHeap); // 4 GiB | ||
| 136 | + #else | ||
| 130 | 137 | uint64_t total_memory = uv_get_total_memory(); | |
| 138 | + #endif | ||
| 131 | 139 | uint64_t constrained_memory = uv_get_constrained_memory(); | |
| 132 | 140 | ||
| 133 | 141 | // Use constrained memory if available, otherwise use total memory | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,7 +122,11 @@ assert( | |||
| 122 | 122 | ); | |
| 123 | 123 | ||
| 124 | 124 | // Validate heap sizes against system memory | |
| 125 | - const totalMemoryMB = Math.floor(os.totalmem() / 1024 / 1024); | ||
| 125 | + // When pointer compression is enabled, the maximum total memory is 4 GB | ||
| 126 | + const totalmem = Math.floor(os.totalmem() / 1024 / 1024); | ||
| 127 | + const totalMemoryMB = process.config.variables.v8_enable_pointer_compression ? | ||
| 128 | + Math.min(4096, totalmem) : | ||
| 129 | + totalmem; | ||
| 126 | 130 | const uint64Max = 2 ** 64 - 1; | |
| 127 | 131 | const constrainedMemory = process.constrainedMemory(); | |
| 128 | 132 | const constrainedMemoryMB = Math.floor(constrainedMemory / 1024 / 1024); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -367,6 +367,9 @@ | |||
| 367 | 367 | ['v8_enable_pointer_compression==1', { | |
| 368 | 368 | 'defines': ['V8_COMPRESS_POINTERS'], | |
| 369 | 369 | }], | |
| 370 | + ['v8_enable_pointer_compression==1 and v8_enable_pointer_compression_shared_cage!=1', { | ||
| 371 | + 'defines': ['V8_COMPRESS_POINTERS_IN_MULTIPLE_CAGES'], | ||
| 372 | + }], | ||
| 370 | 373 | ['v8_enable_pointer_compression_shared_cage==1', { | |
| 371 | 374 | 'defines': ['V8_COMPRESS_POINTERS_IN_SHARED_CAGE'], | |
| 372 | 375 | }], | |
| Back | FazBrowse Home | New Git URL |
0 commit comments