[Flags] Add flag for WebAssembly lazy compilation

Lazy compilation might become one candidate configuration for Liftoff on
mobile. Hence we add the flag now so it will be available in the next
beta release for finching.

[email protected], [email protected]

Bug: 1040030, 1040061
Change-Id: Icb86a4d3c075afc111978f6797634aabd5b98020
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2002568
Reviewed-by: Ross McIlroy <[email protected]>
Reviewed-by: Jochen Eisinger <[email protected]>
Commit-Queue: Clemens Backes <[email protected]>
Cr-Commit-Position: refs/heads/master@{#733294}
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index af58bd40..425ec2f7 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -1699,6 +1699,10 @@
     {"enable-webassembly-code-gc", flag_descriptions::kEnableWasmCodeGCName,
      flag_descriptions::kEnableWasmCodeGCDescription, kOsAll,
      FEATURE_VALUE_TYPE(features::kWebAssemblyCodeGC)},
+    {"enable-webassembly-lazy-compilation",
+     flag_descriptions::kEnableWasmLazyCompilationName,
+     flag_descriptions::kEnableWasmLazyCompilationDescription, kOsAll,
+     FEATURE_VALUE_TYPE(features::kWebAssemblyLazyCompilation)},
     {"enable-webassembly-simd", flag_descriptions::kEnableWasmSimdName,
      flag_descriptions::kEnableWasmSimdDescription, kOsAll,
      FEATURE_VALUE_TYPE(features::kWebAssemblySimd)},
diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json
index 8dc64d3a..40ef855 100644
--- a/chrome/browser/flag-metadata.json
+++ b/chrome/browser/flag-metadata.json
@@ -2092,6 +2092,11 @@
     "expiry_milestone": 83
   },
   {
+    "name": "enable-webassembly-lazy-compilation",
+    "owners": [ "clemensb", "[email protected]" ],
+    "expiry_milestone": 86
+  },
+  {
     "name": "enable-webassembly-simd",
     "owners": [ "gdeepti", "[email protected]" ],
     "expiry_milestone": 83
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
index 45711ac..a4ff231 100644
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -994,6 +994,10 @@
 const char kEnableWasmCodeGCDescription[] =
     "Enables garbage collection of WebAssembly code.";
 
+const char kEnableWasmLazyCompilationName[] = "WebAssembly lazy compilation";
+const char kEnableWasmLazyCompilationDescription[] =
+    "Enables lazy (JIT on first call) compilation of WebAssembly modules.";
+
 const char kEnableWasmSimdName[] = "WebAssembly SIMD support.";
 const char kEnableWasmSimdDescription[] =
     "Enables support for the WebAssembly SIMD proposal.";
@@ -1006,7 +1010,7 @@
 const char kEnableWasmTieringName[] = "WebAssembly tiering";
 const char kEnableWasmTieringDescription[] =
     "Enables tiered compilation of WebAssembly (will tier up to TurboFan if "
-    "#enable-webassembly-baseline is enabled.";
+    "#enable-webassembly-baseline is enabled).";
 
 const char kEvDetailsInPageInfoName[] = "EV certificate details in Page Info.";
 const char kEvDetailsInPageInfoDescription[] =
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
index e401e01..546081e 100644
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -594,6 +594,9 @@
 extern const char kEnableWasmCodeCacheName[];
 extern const char kEnableWasmCodeCacheDescription[];
 
+extern const char kEnableWasmLazyCompilationName[];
+extern const char kEnableWasmLazyCompilationDescription[];
+
 extern const char kEnableWasmSimdName[];
 extern const char kEnableWasmSimdDescription[];
 
diff --git a/content/public/common/content_features.cc b/content/public/common/content_features.cc
index 4a64adb..ab82f09 100644
--- a/content/public/common/content_features.cc
+++ b/content/public/common/content_features.cc
@@ -613,6 +613,10 @@
 const base::Feature kWebAssemblyCodeGC{"WebAssemblyCodeGC",
                                        base::FEATURE_ENABLED_BY_DEFAULT};
 
+// Enable WebAssembly lazy compilation (JIT on first call).
+const base::Feature kWebAssemblyLazyCompilation{
+    "WebAssemblyLazyCompilation", base::FEATURE_DISABLED_BY_DEFAULT};
+
 // Enable WebAssembly SIMD.
 // https://github.com/WebAssembly/Simd
 const base::Feature kWebAssemblySimd{"WebAssemblySimd",
diff --git a/content/public/common/content_features.h b/content/public/common/content_features.h
index ab3a00f..a2572e5 100644
--- a/content/public/common/content_features.h
+++ b/content/public/common/content_features.h
@@ -133,6 +133,7 @@
 CONTENT_EXPORT extern const base::Feature kWebAssembly;
 CONTENT_EXPORT extern const base::Feature kWebAssemblyBaseline;
 CONTENT_EXPORT extern const base::Feature kWebAssemblyCodeGC;
+CONTENT_EXPORT extern const base::Feature kWebAssemblyLazyCompilation;
 CONTENT_EXPORT extern const base::Feature kWebAssemblySimd;
 CONTENT_EXPORT extern const base::Feature kWebAssemblyThreads;
 CONTENT_EXPORT extern const base::Feature kWebAssemblyTiering;
diff --git a/content/renderer/render_process_impl.cc b/content/renderer/render_process_impl.cc
index df1b7395..0b88842 100644
--- a/content/renderer/render_process_impl.cc
+++ b/content/renderer/render_process_impl.cc
@@ -134,6 +134,11 @@
   SetV8FlagIfFeature(features::kWebAssemblyCodeGC, "--wasm-code-gc");
   SetV8FlagIfNotFeature(features::kWebAssemblyCodeGC, "--no-wasm-code-gc");
 
+  SetV8FlagIfFeature(features::kWebAssemblyLazyCompilation,
+                     "--wasm-lazy-compilation");
+  SetV8FlagIfNotFeature(features::kWebAssemblyLazyCompilation,
+                        "--no-wasm-lazy-compilation");
+
   SetV8FlagIfFeature(features::kWebAssemblySimd, "--experimental-wasm-simd");
   SetV8FlagIfNotFeature(features::kWebAssemblySimd,
                         "--no-experimental-wasm-simd");
diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml
index 2fe29b42..a21ca3e 100644
--- a/tools/metrics/histograms/enums.xml
+++ b/tools/metrics/histograms/enums.xml
@@ -38117,6 +38117,7 @@
   <int value="57791920" label="MemoryCoordinator:enabled"/>
   <int value="58099178" label="SecondaryUiMd:enabled"/>
   <int value="58695502" label="NTPButton:disabled"/>
+  <int value="58727839" label="WebAssemblyLazyCompilation:enabled"/>
   <int value="59784035" label="ImeThread:disabled"/>
   <int value="59964519" label="OmniboxEnableClipboardProvider:disabled"/>
   <int value="60023885" label="AutofillNoLocalSaveOnUnmaskSuccess:disabled"/>
@@ -38218,6 +38219,7 @@
   <int value="194895489" label="passive-listeners-default"/>
   <int value="195335115" label="AudioWorkletRealtimeThread:disabled"/>
   <int value="195570937" label="EnableHomeLauncher:disabled"/>
+  <int value="198719062" label="WebAssemblyLazyCompilation:disabled"/>
   <int value="198762155" label="SharingPeerConnectionSender:enabled"/>
   <int value="200347243" label="WebVRExperimentalRendering:disabled"/>
   <int value="201343576" label="enable-password-change-support:enabled"/>