Skip to content

Commit

Permalink
Made it so you can specify the old gen heap size. (flutter#15259)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored and NoamDev committed Feb 27, 2020
1 parent 6f96f30 commit 8d790a1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/settings.cc
Expand Up @@ -58,6 +58,7 @@ std::string Settings::ToString() const {
stream << "assets_path: " << assets_path << std::endl;
stream << "frame_rasterized_callback set: " << !!frame_rasterized_callback
<< std::endl;
stream << "old_gen_heap_size: " << old_gen_heap_size << std::endl;
return stream.str();
}

Expand Down
7 changes: 7 additions & 0 deletions common/settings.h
Expand Up @@ -191,6 +191,13 @@ struct Settings {
// the buffer must be as small as possible.
std::shared_ptr<const fml::Mapping> persistent_isolate_data;

/// Max size of old gen heap size in MB, or 0 for unlimited, -1 for default
/// value.
///
/// See also:
/// https://github.com/dart-lang/sdk/blob/ca64509108b3e7219c50d6c52877c85ab6a35ff2/runtime/vm/flag_list.h#L150
int64_t old_gen_heap_size = -1;

std::string ToString() const;
};

Expand Down
14 changes: 14 additions & 0 deletions runtime/dart_vm.cc
Expand Up @@ -7,6 +7,7 @@
#include <sys/stat.h>

#include <mutex>
#include <sstream>
#include <vector>

#include "flutter/common/settings.h"
Expand Down Expand Up @@ -111,6 +112,12 @@ static const char* kDartTraceStreamsArgs[] = {
"--timeline_streams=Compiler,Dart,Debugger,Embedder,GC,Isolate,VM,API",
};

static std::string DartOldGenHeapSizeArgs(uint64_t heap_size) {
std::ostringstream oss;
oss << "--old_gen_heap_size=" << heap_size;
return oss.str();
}

constexpr char kFileUriPrefix[] = "file://";
constexpr size_t kFileUriPrefixLength = sizeof(kFileUriPrefix) - 1;

Expand Down Expand Up @@ -366,6 +373,13 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
PushBackAll(&args, kDartTraceStartupArgs, fml::size(kDartTraceStartupArgs));
}

std::string old_gen_heap_size_args;
if (settings_.old_gen_heap_size >= 0) {
old_gen_heap_size_args =
DartOldGenHeapSizeArgs(settings_.old_gen_heap_size);
args.push_back(old_gen_heap_size_args.c_str());
}

#if defined(OS_FUCHSIA)
PushBackAll(&args, kDartFuchsiaTraceArgs, fml::size(kDartFuchsiaTraceArgs));
PushBackAll(&args, kDartTraceStreamsArgs, fml::size(kDartTraceStreamsArgs));
Expand Down
10 changes: 10 additions & 0 deletions runtime/dart_vm_unittests.cc
Expand Up @@ -32,5 +32,15 @@ TEST_F(DartVMTest, SimpleIsolateNameServer) {
ASSERT_TRUE(ns->RemoveIsolateNameMapping("foobar"));
}

TEST_F(DartVMTest, OldGenHeapSize) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
auto settings = CreateSettingsForFixture();
settings.old_gen_heap_size = 1024;
auto vm = DartVMRef::Create(settings);
// There is no way to introspect on the heap size so we just assert the vm was
// created.
ASSERT_TRUE(vm);
}

} // namespace testing
} // namespace flutter
1 change: 1 addition & 0 deletions shell/platform/embedder/embedder.cc
Expand Up @@ -664,6 +664,7 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
settings.icu_data_path = icu_data_path;
settings.assets_path = args->assets_path;
settings.leak_vm = !SAFE_ACCESS(args, shutdown_dart_vm_when_done, false);
settings.old_gen_heap_size = SAFE_ACCESS(args, dart_old_gen_heap_size, -1);

if (!flutter::DartVM::IsRunningPrecompiledCode()) {
// Verify the assets path contains Dart 2 kernel assets.
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/embedder/embedder.h
Expand Up @@ -1114,6 +1114,13 @@ typedef struct {
/// absence, platforms views in the scene are ignored and Flutter renders to
/// the root surface as normal.
const FlutterCompositor* compositor;

/// Max size of the old gen heap for the Dart VM in MB, or 0 for unlimited, -1
/// for default value.
///
/// See also:
/// https://github.com/dart-lang/sdk/blob/ca64509108b3e7219c50d6c52877c85ab6a35ff2/runtime/vm/flag_list.h#L150
int64_t dart_old_gen_heap_size;
} FlutterProjectArgs;

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 8d790a1

Please sign in to comment.