Enable WebAssembly DrumBrake interpreter and V8 JIT control (#30703)
* Add WebAssembly jitless mode support with DrumBrake - Create v8 buildflags component for DrumBrake feature detection - Add kBraveWebAssemblyJitless feature flag for chrome://flags - Add kBraveV8OptimizerJit feature flag to control JIT vs jitless mode - Implement IsJitDisabledForSite() to tie V8 optimizer settings to JIT control - Enable --wasm-jitless switch when WebAssembly jitless feature is enabled - Update about_flags.cc with new WebAssembly and V8 JIT configuration options
This commit is contained in:
@@ -109,6 +109,7 @@ include_rules += [
|
||||
"+brave/components/search_engines",
|
||||
"+brave/components/webcompat_reporter/common",
|
||||
"+brave/components/sidebar/browser",
|
||||
"+brave/components/v8/buildflags",
|
||||
"+brave/components/windows_recall",
|
||||
]
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "brave/components/request_otr/common/buildflags/buildflags.h"
|
||||
#include "brave/components/skus/common/features.h"
|
||||
#include "brave/components/speedreader/common/buildflags/buildflags.h"
|
||||
#include "brave/components/v8/buildflags/buildflags.h"
|
||||
#include "brave/components/webcompat/core/common/features.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/buildflags.h"
|
||||
@@ -680,11 +681,33 @@ constexpr flags_ui::FeatureEntry::Choice kVerticalTabCollapseDelayChoices[] = {
|
||||
#define BRAVE_UPDATER_FEATURE_ENTRIES
|
||||
#endif
|
||||
|
||||
#define BRAVE_WEBASSEMBLY_JITLESS_FEATURE_ENTRY \
|
||||
IF_BUILDFLAG(BRAVE_V8_ENABLE_DRUMBRAKE, \
|
||||
EXPAND_FEATURE_ENTRIES({ \
|
||||
"brave-webassembly-jitless", \
|
||||
"Allow WebAssembly to run without JIT", \
|
||||
"Allow WebAssembly to run in interpreter mode even when " \
|
||||
"JIT compilation is disabled. " \
|
||||
"This enables WebAssembly content to work on sites with " \
|
||||
"strict security settings.", \
|
||||
kOsAll, \
|
||||
FEATURE_VALUE_TYPE(features::kBraveWebAssemblyJitless), \
|
||||
}))
|
||||
|
||||
// Keep the last item empty.
|
||||
#define LAST_BRAVE_FEATURE_ENTRIES_ITEM
|
||||
|
||||
#define BRAVE_ABOUT_FLAGS_FEATURE_ENTRIES \
|
||||
EXPAND_FEATURE_ENTRIES( \
|
||||
{ \
|
||||
"brave-v8-jitless-mode", \
|
||||
"V8 Jitless mode", \
|
||||
"Enable V8 jitless mode when optimizations are disabled. " \
|
||||
"V8 runs in jitless mode which reduces performance but improves " \
|
||||
"security. This does not affect all pages.", \
|
||||
kOsAll, \
|
||||
FEATURE_VALUE_TYPE(features::kBraveV8JitlessMode), \
|
||||
}, \
|
||||
{ \
|
||||
"use-dev-updater-url", \
|
||||
"Use dev updater url", \
|
||||
@@ -1239,6 +1262,7 @@ constexpr flags_ui::FeatureEntry::Choice kVerticalTabCollapseDelayChoices[] = {
|
||||
BRAVE_UPGRADE_WHEN_IDLE_FEATURE_ENTRY \
|
||||
BRAVE_EXTENSIONS_MANIFEST_V2 \
|
||||
BRAVE_WORKAROUND_NEW_WINDOW_FLASH \
|
||||
BRAVE_WEBASSEMBLY_JITLESS_FEATURE_ENTRY \
|
||||
BRAVE_ADBLOCK_CUSTOM_SCRIPTLETS \
|
||||
BRAVE_EDUCATION_FEATURE_ENTRIES \
|
||||
BRAVE_UPDATER_FEATURE_ENTRIES \
|
||||
|
||||
@@ -50,6 +50,20 @@ BASE_FEATURE(kBraveDayZeroExperiment,
|
||||
"BraveDayZeroExperiment",
|
||||
base::FEATURE_DISABLED_BY_DEFAULT);
|
||||
|
||||
#if BUILDFLAG(BRAVE_V8_ENABLE_DRUMBRAKE)
|
||||
// Run WebAssembly code in the DrumBrake interpreter instead of the optimizing
|
||||
// compiler. Automatically enabled when V8 is in jitless mode.
|
||||
BASE_FEATURE(kBraveWebAssemblyJitless,
|
||||
"BraveWebAssemblyJitless",
|
||||
base::FEATURE_DISABLED_BY_DEFAULT);
|
||||
#endif // BUILDFLAG(BRAVE_V8_ENABLE_DRUMBRAKE)
|
||||
|
||||
// Controls V8 jitless mode. When enabled, V8 runs in jitless
|
||||
// mode, which reduces performance but improves security.
|
||||
BASE_FEATURE(kBraveV8JitlessMode,
|
||||
"BraveV8JitlessMode",
|
||||
base::FEATURE_DISABLED_BY_DEFAULT);
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
// Enable new onboarding on Android
|
||||
BASE_FEATURE(kNewAndroidOnboarding,
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "base/feature_list.h"
|
||||
#include "base/metrics/field_trial_params.h"
|
||||
#include "brave/components/v8/buildflags/buildflags.h"
|
||||
|
||||
namespace features {
|
||||
|
||||
@@ -20,6 +21,10 @@ BASE_DECLARE_FEATURE(kBraveCopyCleanLinkFromJs);
|
||||
BASE_DECLARE_FEATURE(kBraveOverrideDownloadDangerLevel);
|
||||
BASE_DECLARE_FEATURE(kBraveWebViewRoundedCorners);
|
||||
BASE_DECLARE_FEATURE(kBraveDayZeroExperiment);
|
||||
#if BUILDFLAG(BRAVE_V8_ENABLE_DRUMBRAKE)
|
||||
BASE_DECLARE_FEATURE(kBraveWebAssemblyJitless);
|
||||
#endif // BUILDFLAG(BRAVE_V8_ENABLE_DRUMBRAKE)
|
||||
BASE_DECLARE_FEATURE(kBraveV8JitlessMode);
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
BASE_DECLARE_FEATURE(kBraveAndroidDynamicColors);
|
||||
BASE_DECLARE_FEATURE(kNewAndroidOnboarding);
|
||||
|
||||
@@ -156,6 +156,7 @@
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
|
||||
#include "third_party/blink/public/common/features.h"
|
||||
#include "third_party/blink/public/common/loader/url_loader_throttle.h"
|
||||
#include "third_party/blink/public/common/switches.h"
|
||||
#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom.h"
|
||||
#include "third_party/widevine/cdm/buildflags.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
@@ -935,9 +936,20 @@ void BraveContentBrowserClient::AppendExtraCommandLineSwitches(
|
||||
int child_process_id) {
|
||||
ChromeContentBrowserClient::AppendExtraCommandLineSwitches(command_line,
|
||||
child_process_id);
|
||||
|
||||
std::string process_type =
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
if (process_type == switches::kRendererProcess) {
|
||||
#if BUILDFLAG(BRAVE_V8_ENABLE_DRUMBRAKE)
|
||||
if (base::FeatureList::IsEnabled(features::kBraveWebAssemblyJitless)) {
|
||||
content::RenderProcessHost* process =
|
||||
content::RenderProcessHost::FromID(child_process_id);
|
||||
if (process && process->IsJitDisabled()) {
|
||||
command_line->AppendSwitchASCII(blink::switches::kJavaScriptFlags,
|
||||
"--wasm-jitless");
|
||||
}
|
||||
}
|
||||
#endif // BUILDFLAG(BRAVE_V8_ENABLE_DRUMBRAKE)
|
||||
// Command line parameters from the browser process are propagated to the
|
||||
// renderers *after* ContentBrowserClient::AppendExtraCommandLineSwitches()
|
||||
// is called from RenderProcessHostImpl::AppendRendererCommandLine(). This
|
||||
@@ -1392,3 +1404,17 @@ bool BraveContentBrowserClient::AllowSignedExchange(
|
||||
// exchanges.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BraveContentBrowserClient::IsJitDisabledForSite(
|
||||
content::BrowserContext* browser_context,
|
||||
const GURL& site_url) {
|
||||
// When v8-jitless-mode flag is enabled, V8 optimizer
|
||||
// settings should disable JIT completely, not just optimizations
|
||||
if (AreV8OptimizationsDisabledForSite(browser_context, site_url) &&
|
||||
base::FeatureList::IsEnabled(features::kBraveV8JitlessMode)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ChromeContentBrowserClient::IsJitDisabledForSite(browser_context,
|
||||
site_url);
|
||||
}
|
||||
|
||||
@@ -99,6 +99,9 @@ class BraveContentBrowserClient : public ChromeContentBrowserClient {
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id) override;
|
||||
|
||||
bool IsJitDisabledForSite(content::BrowserContext* browser_context,
|
||||
const GURL& site_url) override;
|
||||
|
||||
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
|
||||
CreateURLLoaderThrottles(
|
||||
const network::ResourceRequest& request,
|
||||
|
||||
@@ -228,6 +228,7 @@ brave_chrome_browser_deps = [
|
||||
"//brave/components/speech_to_text:buildflags",
|
||||
"//brave/components/speedreader/common/buildflags",
|
||||
"//brave/components/tor/buildflags",
|
||||
"//brave/components/v8/buildflags",
|
||||
"//brave/components/version_info",
|
||||
"//brave/components/web_discovery/buildflags",
|
||||
"//brave/components/webcompat/content/browser",
|
||||
|
||||
@@ -441,6 +441,11 @@ Config.prototype.buildArgs = function () {
|
||||
use_libfuzzer: this.use_libfuzzer,
|
||||
enable_update_notifications: this.isOfficialBuild(),
|
||||
generate_about_credits: true,
|
||||
v8_enable_drumbrake:
|
||||
(this.targetArch === 'x64' || this.targetArch === 'arm64')
|
||||
&& (this.targetOS === 'win'
|
||||
|| this.targetOS === 'linux'
|
||||
|| this.targetOS === 'mac'),
|
||||
}
|
||||
|
||||
if (this.targetOS !== 'ios') {
|
||||
|
||||
@@ -16,6 +16,7 @@ brave_chromium_src_chrome_browser_deps = [
|
||||
"//brave/components/commander/common/buildflags",
|
||||
"//brave/components/playlist/core/common/buildflags",
|
||||
"//brave/components/text_recognition/common/buildflags",
|
||||
"//brave/components/v8/buildflags",
|
||||
"//chrome/common:channel_info",
|
||||
"//components/version_info",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2025 The Brave Authors. All rights reserved.
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
import("//brave/build/config.gni")
|
||||
import("//build/buildflag_header.gni")
|
||||
import("//v8/gni/v8.gni")
|
||||
|
||||
buildflag_header("buildflags") {
|
||||
header = "buildflags.h"
|
||||
flags = [ "BRAVE_V8_ENABLE_DRUMBRAKE=$v8_enable_drumbrake" ]
|
||||
}
|
||||
Reference in New Issue
Block a user