From 37b7db0653cfa192561e5adfff47df51573f3f95 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Tue, 22 Oct 2024 23:09:20 +0000 Subject: [PATCH] [io] Limit the IOService to 1 thread when running with --deterministic. TEST=locally build the SDK twice without RBE Bug: https://github.com/dart-lang/sdk/issues/56884 Change-Id: I59110f92c737fb1137e12114f6bcaacfd6283347 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391463 Reviewed-by: Brian Quinlan Commit-Queue: Ryan Macnak --- runtime/bin/io_service.cc | 4 +++- runtime/bin/io_service.h | 5 +++++ runtime/bin/io_service_no_ssl.cc | 4 +++- runtime/bin/io_service_no_ssl.h | 5 +++++ runtime/bin/main_options.cc | 9 +++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/runtime/bin/io_service.cc b/runtime/bin/io_service.cc index d16dda2be9c..673a0cee1f1 100644 --- a/runtime/bin/io_service.cc +++ b/runtime/bin/io_service.cc @@ -54,9 +54,11 @@ void IOServiceCallback(Dart_Port dest_port_id, Dart_CObject* message) { Dart_PostCObject(reply_port_id, result.AsApiCObject()); } +intptr_t IOService::max_concurrency_ = 32; + Dart_Port IOService::GetServicePort() { return Dart_NewConcurrentNativePort("IOService", IOServiceCallback, - /*max_concurrency=*/32); + max_concurrency_); } void FUNCTION_NAME(IOService_NewServicePort)(Dart_NativeArguments args) { diff --git a/runtime/bin/io_service.h b/runtime/bin/io_service.h index e0577a8f605..d440f0f738f 100644 --- a/runtime/bin/io_service.h +++ b/runtime/bin/io_service.h @@ -70,7 +70,12 @@ class IOService { static Dart_Port GetServicePort(); + static intptr_t max_concurrency() { return max_concurrency_; } + static void set_max_concurrency(intptr_t value) { max_concurrency_ = value; } + private: + static intptr_t max_concurrency_; + DISALLOW_ALLOCATION(); DISALLOW_IMPLICIT_CONSTRUCTORS(IOService); }; diff --git a/runtime/bin/io_service_no_ssl.cc b/runtime/bin/io_service_no_ssl.cc index 7e6d83cdca4..406ad89b6df 100644 --- a/runtime/bin/io_service_no_ssl.cc +++ b/runtime/bin/io_service_no_ssl.cc @@ -52,9 +52,11 @@ void IOServiceCallback(Dart_Port dest_port_id, Dart_CObject* message) { Dart_PostCObject(reply_port_id, result.AsApiCObject()); } +intptr_t IOService::max_concurrency_ = 32; + Dart_Port IOService::GetServicePort() { return Dart_NewConcurrentNativePort("IOService", IOServiceCallback, - /*max_concurrency=*/32); + max_concurrency_); } void FUNCTION_NAME(IOService_NewServicePort)(Dart_NativeArguments args) { diff --git a/runtime/bin/io_service_no_ssl.h b/runtime/bin/io_service_no_ssl.h index 7e9d16f6f3d..9ab2762e6ad 100644 --- a/runtime/bin/io_service_no_ssl.h +++ b/runtime/bin/io_service_no_ssl.h @@ -71,7 +71,12 @@ class IOService { static Dart_Port GetServicePort(); + static intptr_t max_concurrency() { return max_concurrency_; } + static void set_max_concurrency(intptr_t value) { max_concurrency_ = value; } + private: + static intptr_t max_concurrency_; + DISALLOW_ALLOCATION(); DISALLOW_IMPLICIT_CONSTRUCTORS(IOService); }; diff --git a/runtime/bin/main_options.cc b/runtime/bin/main_options.cc index a6daa22d955..98ec256732f 100644 --- a/runtime/bin/main_options.cc +++ b/runtime/bin/main_options.cc @@ -11,6 +11,11 @@ #include "bin/dartdev_isolate.h" #include "bin/error_exit.h" #include "bin/file_system_watcher.h" +#if defined(DART_IO_SECURE_SOCKET_DISABLED) +#include "bin/io_service_no_ssl.h" +#else // defined(DART_IO_SECURE_SOCKET_DISABLED) +#include "bin/io_service.h" +#endif // defined(DART_IO_SECURE_SOCKET_DISABLED) #include "bin/options.h" #include "bin/platform.h" #include "bin/utils.h" @@ -606,6 +611,10 @@ bool Options::ParseArguments(int argc, FileSystemWatcher::set_delayed_filewatch_callback( Options::delayed_filewatch_callback()); + if (Options::deterministic()) { + IOService::set_max_concurrency(1); + } + // The arguments to the VM are at positions 1 through i-1 in argv. Platform::SetExecutableArguments(i, argv);