2012-04-21 01:36:23 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2012-05-01 22:15:26 +00:00
|
|
|
#include "vm/benchmark_test.h"
|
|
|
|
|
2013-05-22 16:07:25 +00:00
|
|
|
#include "bin/builtin.h"
|
2012-05-01 22:15:26 +00:00
|
|
|
#include "bin/file.h"
|
2016-02-04 17:18:31 +00:00
|
|
|
#include "bin/isolate_data.h"
|
2017-08-15 00:02:22 +00:00
|
|
|
#include "bin/process.h"
|
2018-09-21 15:48:17 +00:00
|
|
|
#include "bin/reference_counting.h"
|
2019-08-17 00:07:40 +00:00
|
|
|
#include "bin/vmservice_impl.h"
|
2012-05-01 22:15:26 +00:00
|
|
|
|
2012-04-25 00:35:15 +00:00
|
|
|
#include "platform/assert.h"
|
2014-04-02 17:39:32 +00:00
|
|
|
#include "platform/globals.h"
|
2020-06-25 03:36:41 +00:00
|
|
|
#include "platform/utils.h"
|
2012-04-25 00:35:15 +00:00
|
|
|
|
2021-09-16 00:13:34 +00:00
|
|
|
#include "vm/app_snapshot.h"
|
2012-04-21 01:36:23 +00:00
|
|
|
#include "vm/dart_api_impl.h"
|
[vm] Consolidate the *WriteStream hierarchy.
All *WriteStream classes are now part of the same hierarchy:
class BaseWriteStream : ValueObject;
Base class for all *WriteStreams. Provides all the methods from
the old WriteStream except for buffer() and SetPosition()
(relegated to NonStreamingWriteStreams). Has one pure virtual
method Realloc that must be overridden by concrete subclasses.
class NonStreamingWriteStream : BaseWriteStream;
Base class for all *WriteStreams where the entire stream is available
at all times (i.e., no flushing to an external sink). Extends the
public BaseWriteStream API with buffer() (for accessing the stream
contents) and SetPosition() (for changing the current stream pointer
to the given absolute position in the stream).
class MallocWriteStream : NonStreamingWriteStream;
Uses realloc to reallocate the internal buffer. Almost the same as
the old WriteStream, except that it only takes an initial size. Adds
one public method Steal() for taking ownership of the current buffer
contents (after which the buffer is reset to an empty state). Instead
of passing a pointer to a buffer, the internal buffer must be accessed
via either Steal() or buffer(), which allows access to the current
stream contents without changing ownership or resetting the stream.
The internal buffer is freed on stream destruction.
class ZoneWriteStream: NonStreamingWriteStream;
Takes a zone and reallocates the internal buffer in that zone. No
additional public methods beyond those available from
NonStreamingWriteStream.
class StreamingWriteStream : BaseWriteStream;
Uses realloc to reallocate the internal buffer. Generally same as
before, where the contents of the stream are periodically flushed
using Dart_StreamingWriteCallback. Since it extends BaseWriteStream,
there are now more methods available for writing data to the stream
than just Print/VPrint/WriteBytes. Since portions of the stream may be
flushed and thus no longer in the internal buffer, does not provide
access to the contents of the stream or a way to reposition the
current stream pointer. Flushes any unflushed data and frees the
internal buffer on stream destruction.
Also refactor things so that write streams are passed to appropriate
recipients, instead of the recipients taking arguments they only used to
create a WriteStream internally. Thus, recipients now can just specify
the appropriate base class for the public API used:
* BaseWriteStream for just writing to the stream, or
* NonStreamingWriteStream if re-positioning or the stream contents are
needed.
Change-Id: I419096ecd9331483d168b079fca55b69ef397f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
|
|
|
#include "vm/datastream.h"
|
2021-07-29 16:55:55 +00:00
|
|
|
#include "vm/message_snapshot.h"
|
2012-05-01 01:00:04 +00:00
|
|
|
#include "vm/stack_frame.h"
|
2018-10-10 21:39:45 +00:00
|
|
|
#include "vm/timer.h"
|
2012-04-21 01:36:23 +00:00
|
|
|
|
2013-04-25 14:22:30 +00:00
|
|
|
using dart::bin::File;
|
|
|
|
|
2012-04-21 01:36:23 +00:00
|
|
|
namespace dart {
|
|
|
|
|
|
|
|
Benchmark* Benchmark::first_ = NULL;
|
|
|
|
Benchmark* Benchmark::tail_ = NULL;
|
2012-05-01 22:15:26 +00:00
|
|
|
const char* Benchmark::executable_ = NULL;
|
2012-04-21 01:36:23 +00:00
|
|
|
|
2012-05-01 22:15:26 +00:00
|
|
|
void Benchmark::RunAll(const char* executable) {
|
|
|
|
SetExecutable(executable);
|
2012-04-21 01:36:23 +00:00
|
|
|
Benchmark* benchmark = first_;
|
|
|
|
while (benchmark != NULL) {
|
|
|
|
benchmark->RunBenchmark();
|
|
|
|
benchmark = benchmark->next_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 01:00:04 +00:00
|
|
|
//
|
|
|
|
// Measure compile of all functions in dart core lib classes.
|
|
|
|
//
|
2012-04-21 01:36:23 +00:00
|
|
|
BENCHMARK(CorelibCompileAll) {
|
2013-05-22 16:07:25 +00:00
|
|
|
bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary);
|
|
|
|
bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary);
|
2018-01-18 16:38:54 +00:00
|
|
|
bin::Builtin::SetNativeResolver(bin::Builtin::kCLILibrary);
|
2016-02-01 18:57:34 +00:00
|
|
|
TransitionNativeToVM transition(thread);
|
2018-10-31 19:51:52 +00:00
|
|
|
StackZone zone(thread);
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2012-04-21 01:36:23 +00:00
|
|
|
timer.Start();
|
2018-10-23 14:16:43 +00:00
|
|
|
const Error& error =
|
|
|
|
Error::Handle(Library::CompileAll(/*ignore_error=*/true));
|
2012-08-28 21:18:21 +00:00
|
|
|
if (!error.IsNull()) {
|
|
|
|
OS::PrintErr("Unexpected error in CorelibCompileAll benchmark:\n%s",
|
|
|
|
error.ToErrorCString());
|
|
|
|
}
|
2015-09-16 18:18:31 +00:00
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
2019-06-06 21:36:02 +00:00
|
|
|
// This file is created by the target //runtime/bin:dart_kernel_platform_cc
|
|
|
|
// which is depended on by run_vm_tests.
|
|
|
|
static char* ComputeKernelServicePath(const char* arg) {
|
|
|
|
char buffer[2048];
|
2020-06-25 03:36:41 +00:00
|
|
|
char* kernel_service_path = Utils::StrDup(File::GetCanonicalPath(NULL, arg));
|
2019-06-06 21:36:02 +00:00
|
|
|
EXPECT(kernel_service_path != NULL);
|
|
|
|
const char* compiler_path = "%s%sgen%skernel_service.dill";
|
|
|
|
const char* path_separator = File::PathSeparator();
|
|
|
|
ASSERT(path_separator != NULL && strlen(path_separator) == 1);
|
|
|
|
char* ptr = strrchr(kernel_service_path, *path_separator);
|
|
|
|
while (ptr != NULL) {
|
|
|
|
*ptr = '\0';
|
|
|
|
Utils::SNPrint(buffer, ARRAY_SIZE(buffer), compiler_path,
|
|
|
|
kernel_service_path, path_separator, path_separator);
|
|
|
|
if (File::Exists(NULL, buffer)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ptr = strrchr(kernel_service_path, *path_separator);
|
|
|
|
}
|
|
|
|
free(kernel_service_path);
|
|
|
|
if (ptr == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-06-25 03:36:41 +00:00
|
|
|
return Utils::StrDup(buffer);
|
2019-06-06 21:36:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 01:00:04 +00:00
|
|
|
//
|
|
|
|
// Measure creation of core isolate from a snapshot.
|
|
|
|
//
|
2012-04-21 01:36:23 +00:00
|
|
|
BENCHMARK(CorelibIsolateStartup) {
|
2014-06-06 01:28:50 +00:00
|
|
|
const int kNumIterations = 1000;
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2015-11-25 19:07:22 +00:00
|
|
|
Isolate* isolate = thread->isolate();
|
2016-02-01 18:57:34 +00:00
|
|
|
Dart_ExitIsolate();
|
2012-04-21 01:36:23 +00:00
|
|
|
for (int i = 0; i < kNumIterations; i++) {
|
2014-06-06 01:28:50 +00:00
|
|
|
timer.Start();
|
|
|
|
TestCase::CreateTestIsolate();
|
|
|
|
timer.Stop();
|
2012-04-21 01:36:23 +00:00
|
|
|
Dart_ShutdownIsolate();
|
|
|
|
}
|
2014-06-06 01:28:50 +00:00
|
|
|
benchmark->set_score(timer.TotalElapsedTime() / kNumIterations);
|
2016-02-01 18:57:34 +00:00
|
|
|
Dart_EnterIsolate(reinterpret_cast<Dart_Isolate>(isolate));
|
2012-04-25 00:35:15 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 01:00:04 +00:00
|
|
|
//
|
|
|
|
// Measure invocation of Dart API functions.
|
|
|
|
//
|
|
|
|
static void InitNativeFields(Dart_NativeArguments args) {
|
2012-04-25 00:35:15 +00:00
|
|
|
int count = Dart_GetNativeArgumentCount(args);
|
|
|
|
EXPECT_EQ(1, count);
|
|
|
|
|
|
|
|
Dart_Handle recv = Dart_GetNativeArgument(args, 0);
|
2012-08-06 07:55:53 +00:00
|
|
|
EXPECT_VALID(recv);
|
2012-04-25 00:35:15 +00:00
|
|
|
Dart_Handle result = Dart_SetNativeInstanceField(recv, 0, 7);
|
2012-08-06 07:55:53 +00:00
|
|
|
EXPECT_VALID(result);
|
2012-04-25 00:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The specific api functions called here are a bit arbitrary. We are
|
|
|
|
// trying to get a sense of the overhead for using the dart api.
|
2012-05-01 01:00:04 +00:00
|
|
|
static void UseDartApi(Dart_NativeArguments args) {
|
2012-04-25 00:35:15 +00:00
|
|
|
int count = Dart_GetNativeArgumentCount(args);
|
|
|
|
EXPECT_EQ(3, count);
|
|
|
|
|
2013-08-02 22:47:26 +00:00
|
|
|
// Get native field from receiver.
|
|
|
|
intptr_t receiver_value;
|
|
|
|
Dart_Handle result = Dart_GetNativeReceiver(args, &receiver_value);
|
|
|
|
EXPECT_VALID(result);
|
|
|
|
EXPECT_EQ(7, receiver_value);
|
2012-04-25 00:35:15 +00:00
|
|
|
|
|
|
|
// Get param1.
|
|
|
|
Dart_Handle param1 = Dart_GetNativeArgument(args, 1);
|
2012-08-06 07:55:53 +00:00
|
|
|
EXPECT_VALID(param1);
|
2012-04-25 00:35:15 +00:00
|
|
|
EXPECT(Dart_IsInteger(param1));
|
|
|
|
bool fits = false;
|
2013-08-02 22:47:26 +00:00
|
|
|
result = Dart_IntegerFitsIntoInt64(param1, &fits);
|
2012-08-06 07:55:53 +00:00
|
|
|
EXPECT_VALID(result);
|
|
|
|
EXPECT(fits);
|
2012-04-25 00:35:15 +00:00
|
|
|
int64_t value1;
|
|
|
|
result = Dart_IntegerToInt64(param1, &value1);
|
2012-08-06 07:55:53 +00:00
|
|
|
EXPECT_VALID(result);
|
2012-04-25 00:35:15 +00:00
|
|
|
EXPECT_LE(0, value1);
|
|
|
|
EXPECT_LE(value1, 1000000);
|
|
|
|
|
|
|
|
// Return param + receiver.field.
|
2013-08-02 22:47:26 +00:00
|
|
|
Dart_SetReturnValue(args, Dart_NewInteger(value1 * receiver_value));
|
2012-04-25 00:35:15 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 17:47:56 +00:00
|
|
|
static Dart_NativeFunction bm_uda_lookup(Dart_Handle name,
|
|
|
|
int argument_count,
|
|
|
|
bool* auto_setup_scope) {
|
|
|
|
ASSERT(auto_setup_scope != NULL);
|
2016-02-01 18:57:34 +00:00
|
|
|
*auto_setup_scope = true;
|
2012-04-25 00:35:15 +00:00
|
|
|
const char* cstr = NULL;
|
|
|
|
Dart_Handle result = Dart_StringToCString(name, &cstr);
|
2012-08-06 07:55:53 +00:00
|
|
|
EXPECT_VALID(result);
|
2012-04-25 00:35:15 +00:00
|
|
|
if (strcmp(cstr, "init") == 0) {
|
|
|
|
return InitNativeFields;
|
|
|
|
} else {
|
|
|
|
return UseDartApi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK(UseDartApi) {
|
2012-06-28 21:04:58 +00:00
|
|
|
const int kNumIterations = 1000000;
|
2021-09-08 13:39:34 +00:00
|
|
|
const char* kScriptChars = R"(
|
|
|
|
import 'dart:nativewrappers';
|
|
|
|
|
|
|
|
class Class extends NativeFieldWrapperClass1 {
|
|
|
|
@pragma("vm:external-name", "init")
|
|
|
|
external void init();
|
|
|
|
@pragma("vm:external-name", "method")
|
|
|
|
external int method(int param1, int param2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void benchmark(int count) {
|
|
|
|
Class c = Class();
|
|
|
|
c.init();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
c.method(i,7);
|
|
|
|
}
|
|
|
|
})";
|
2012-04-25 00:35:15 +00:00
|
|
|
|
2020-06-02 21:29:03 +00:00
|
|
|
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, bm_uda_lookup,
|
|
|
|
RESOLVED_USER_TEST_URI, false);
|
2018-12-14 15:25:53 +00:00
|
|
|
Dart_Handle result = Dart_FinalizeLoading(false);
|
2014-07-22 20:08:15 +00:00
|
|
|
EXPECT_VALID(result);
|
2012-04-25 00:35:15 +00:00
|
|
|
|
|
|
|
Dart_Handle args[1];
|
|
|
|
args[0] = Dart_NewInteger(kNumIterations);
|
2012-07-11 00:11:58 +00:00
|
|
|
|
|
|
|
// Warmup first to avoid compilation jitters.
|
2018-05-03 17:34:13 +00:00
|
|
|
result = Dart_Invoke(lib, NewString("benchmark"), 1, args);
|
|
|
|
EXPECT_VALID(result);
|
2012-07-11 00:11:58 +00:00
|
|
|
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2012-07-11 00:11:58 +00:00
|
|
|
timer.Start();
|
2018-05-03 17:34:13 +00:00
|
|
|
result = Dart_Invoke(lib, NewString("benchmark"), 1, args);
|
|
|
|
EXPECT_VALID(result);
|
2012-04-25 00:35:15 +00:00
|
|
|
timer.Stop();
|
2012-04-21 01:36:23 +00:00
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
2012-04-25 00:35:15 +00:00
|
|
|
benchmark->set_score(elapsed_time);
|
2012-04-21 01:36:23 +00:00
|
|
|
}
|
|
|
|
|
[vm] Native API: Make Dart_NewWeakPersistentHandle not auto delete
Changes Dart_NewWeakPersistentHandle to no longer auto delete the
weak persistent handle.
Changes the signatures of WeakPersistentHandleFinalizers to no longer
have access to the handle.
Flutter PR: https://github.com/flutter/engine/pull/19843
g3 presubmit: cl/318028238
Issue: https://github.com/dart-lang/sdk/issues/42312
TEST=runtime/vm/dart_api_impl_test.cc
Change-Id: I3f77db9954d9486759f903b78c03a494f73c68ba
Cq-Include-Trybots:dart/try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-msan-linux-release-x64-try,vm-kernel-precomp-msan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-mac-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-nnbd-linux-debug-x64-try,analyzer-nnbd-linux-release-try,front-end-nnbd-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151525
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-11-03 10:27:44 +00:00
|
|
|
static void NoopFinalizer(void* isolate_callback_data, void* peer) {}
|
2018-06-04 23:44:39 +00:00
|
|
|
|
2012-08-29 18:06:17 +00:00
|
|
|
//
|
|
|
|
// Measure time accessing internal and external strings.
|
|
|
|
//
|
|
|
|
BENCHMARK(DartStringAccess) {
|
|
|
|
const int kNumIterations = 10000000;
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2012-08-29 18:06:17 +00:00
|
|
|
timer.Start();
|
|
|
|
Dart_EnterScope();
|
|
|
|
|
|
|
|
// Create strings.
|
2016-11-08 21:54:47 +00:00
|
|
|
uint8_t data8[] = {'o', 'n', 'e', 0xFF};
|
2012-08-29 18:06:17 +00:00
|
|
|
int external_peer_data = 123;
|
2013-08-22 17:10:37 +00:00
|
|
|
intptr_t char_size;
|
|
|
|
intptr_t str_len;
|
2012-11-29 23:43:47 +00:00
|
|
|
Dart_Handle external_string = Dart_NewExternalLatin1String(
|
2018-06-04 23:44:39 +00:00
|
|
|
data8, ARRAY_SIZE(data8), &external_peer_data, sizeof(data8),
|
|
|
|
NoopFinalizer);
|
2012-10-31 17:56:46 +00:00
|
|
|
Dart_Handle internal_string = NewString("two");
|
2012-08-29 18:06:17 +00:00
|
|
|
|
|
|
|
// Run benchmark.
|
|
|
|
for (int64_t i = 0; i < kNumIterations; i++) {
|
|
|
|
EXPECT(Dart_IsString(internal_string));
|
|
|
|
EXPECT(!Dart_IsExternalString(internal_string));
|
|
|
|
EXPECT_VALID(external_string);
|
|
|
|
EXPECT(Dart_IsExternalString(external_string));
|
|
|
|
void* external_peer = NULL;
|
2016-11-08 21:54:47 +00:00
|
|
|
EXPECT_VALID(Dart_StringGetProperties(external_string, &char_size, &str_len,
|
2013-08-22 17:10:37 +00:00
|
|
|
&external_peer));
|
|
|
|
EXPECT_EQ(1, char_size);
|
|
|
|
EXPECT_EQ(4, str_len);
|
2012-08-29 18:06:17 +00:00
|
|
|
EXPECT_EQ(&external_peer_data, external_peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dart_ExitScope();
|
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
2019-06-06 21:36:02 +00:00
|
|
|
static void vmservice_resolver(Dart_NativeArguments args) {}
|
|
|
|
|
|
|
|
static Dart_NativeFunction NativeResolver(Dart_Handle name,
|
|
|
|
int arg_count,
|
|
|
|
bool* auto_setup_scope) {
|
|
|
|
ASSERT(auto_setup_scope != NULL);
|
|
|
|
*auto_setup_scope = false;
|
|
|
|
return &vmservice_resolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Measure compile of all kernel Service(CFE) functions.
|
|
|
|
//
|
|
|
|
BENCHMARK(KernelServiceCompileAll) {
|
2021-07-28 18:38:30 +00:00
|
|
|
// kernel_service.dill is built with sound null safety.
|
|
|
|
if (FLAG_sound_null_safety != kNullSafetyOptionStrong) {
|
2020-05-26 22:40:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-05-22 16:07:25 +00:00
|
|
|
bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary);
|
|
|
|
bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary);
|
2018-01-18 16:38:54 +00:00
|
|
|
bin::Builtin::SetNativeResolver(bin::Builtin::kCLILibrary);
|
2019-06-06 21:36:02 +00:00
|
|
|
char* dill_path = ComputeKernelServicePath(Benchmark::Executable());
|
|
|
|
File* file = File::Open(NULL, dill_path, File::kRead);
|
|
|
|
EXPECT(file != NULL);
|
|
|
|
bin::RefCntReleaseScope<File> rs(file);
|
|
|
|
intptr_t kernel_buffer_size = file->Length();
|
|
|
|
uint8_t* kernel_buffer =
|
|
|
|
reinterpret_cast<uint8_t*>(malloc(kernel_buffer_size));
|
|
|
|
bool read_fully = file->ReadFully(kernel_buffer, kernel_buffer_size);
|
|
|
|
EXPECT(read_fully);
|
|
|
|
Dart_Handle result =
|
|
|
|
Dart_LoadScriptFromKernel(kernel_buffer, kernel_buffer_size);
|
|
|
|
EXPECT_VALID(result);
|
|
|
|
Dart_Handle service_lib = Dart_LookupLibrary(NewString("dart:vmservice_io"));
|
|
|
|
ASSERT(!Dart_IsError(service_lib));
|
2020-06-02 21:29:03 +00:00
|
|
|
Dart_SetNativeResolver(service_lib, NativeResolver, NULL);
|
2019-06-06 21:36:02 +00:00
|
|
|
result = Dart_FinalizeLoading(false);
|
|
|
|
EXPECT_VALID(result);
|
|
|
|
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2012-05-01 01:00:04 +00:00
|
|
|
timer.Start();
|
2016-02-25 15:53:39 +00:00
|
|
|
#if !defined(PRODUCT)
|
2016-02-12 23:40:07 +00:00
|
|
|
const bool old_flag = FLAG_background_compilation;
|
|
|
|
FLAG_background_compilation = false;
|
2016-02-25 15:53:39 +00:00
|
|
|
#endif
|
2019-06-06 21:36:02 +00:00
|
|
|
result = Dart_CompileAll();
|
2016-02-25 15:53:39 +00:00
|
|
|
#if !defined(PRODUCT)
|
2016-02-12 23:40:07 +00:00
|
|
|
FLAG_background_compilation = old_flag;
|
2016-02-25 15:53:39 +00:00
|
|
|
#endif
|
2012-08-06 07:55:53 +00:00
|
|
|
EXPECT_VALID(result);
|
2012-05-01 01:00:04 +00:00
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
2019-06-06 21:36:02 +00:00
|
|
|
free(dill_path);
|
|
|
|
free(kernel_buffer);
|
2012-05-01 01:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Measure frame lookup during stack traversal.
|
|
|
|
//
|
|
|
|
static void StackFrame_accessFrame(Dart_NativeArguments args) {
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2012-05-01 01:00:04 +00:00
|
|
|
timer.Start();
|
2018-10-31 19:51:52 +00:00
|
|
|
{
|
|
|
|
Thread* thread = Thread::Current();
|
|
|
|
TransitionNativeToVM transition(thread);
|
|
|
|
const int kNumIterations = 100;
|
|
|
|
Code& code = Code::Handle(thread->zone());
|
|
|
|
for (int i = 0; i < kNumIterations; i++) {
|
|
|
|
StackFrameIterator frames(ValidationPolicy::kDontValidateFrames, thread,
|
|
|
|
StackFrameIterator::kNoCrossThreadIteration);
|
|
|
|
StackFrame* frame = frames.NextFrame();
|
|
|
|
while (frame != NULL) {
|
|
|
|
if (frame->IsStubFrame()) {
|
|
|
|
code = frame->LookupDartCode();
|
|
|
|
EXPECT(code.function() == Function::null());
|
|
|
|
} else if (frame->IsDartFrame()) {
|
2020-10-28 17:42:35 +00:00
|
|
|
code = frame->LookupDartCode();
|
|
|
|
EXPECT(code.function() != Function::null());
|
2018-10-31 19:51:52 +00:00
|
|
|
}
|
|
|
|
frame = frames.NextFrame();
|
2012-05-01 01:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
Dart_SetReturnValue(args, Dart_NewInteger(elapsed_time));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Dart_NativeFunction StackFrameNativeResolver(Dart_Handle name,
|
2013-12-19 17:47:56 +00:00
|
|
|
int arg_count,
|
|
|
|
bool* auto_setup_scope) {
|
|
|
|
ASSERT(auto_setup_scope != NULL);
|
|
|
|
*auto_setup_scope = false;
|
2012-05-01 01:00:04 +00:00
|
|
|
return &StackFrame_accessFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unit test case to verify stack frame iteration.
|
|
|
|
BENCHMARK(FrameLookup) {
|
|
|
|
const char* kScriptChars =
|
|
|
|
"class StackFrame {"
|
|
|
|
" static int accessFrame() native \"StackFrame_accessFrame\";"
|
|
|
|
"} "
|
|
|
|
"class First {"
|
|
|
|
" First() { }"
|
|
|
|
" int method1(int param) {"
|
|
|
|
" if (param == 1) {"
|
|
|
|
" param = method2(200);"
|
|
|
|
" } else {"
|
|
|
|
" param = method2(100);"
|
|
|
|
" }"
|
|
|
|
" return param;"
|
|
|
|
" }"
|
|
|
|
" int method2(int param) {"
|
|
|
|
" if (param == 200) {"
|
|
|
|
" return First.staticmethod(this, param);"
|
|
|
|
" } else {"
|
|
|
|
" return First.staticmethod(this, 10);"
|
|
|
|
" }"
|
|
|
|
" }"
|
|
|
|
" static int staticmethod(First obj, int param) {"
|
|
|
|
" if (param == 10) {"
|
|
|
|
" return obj.method3(10);"
|
|
|
|
" } else {"
|
|
|
|
" return obj.method3(200);"
|
|
|
|
" }"
|
|
|
|
" }"
|
|
|
|
" int method3(int param) {"
|
|
|
|
" return StackFrame.accessFrame();"
|
|
|
|
" }"
|
|
|
|
"}"
|
|
|
|
"class StackFrameTest {"
|
|
|
|
" static int testMain() {"
|
|
|
|
" First obj = new First();"
|
|
|
|
" return obj.method1(1);"
|
|
|
|
" }"
|
|
|
|
"}";
|
2020-06-02 21:29:03 +00:00
|
|
|
Dart_Handle lib =
|
|
|
|
TestCase::LoadTestScript(kScriptChars, StackFrameNativeResolver);
|
2012-10-31 17:56:46 +00:00
|
|
|
Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest"));
|
|
|
|
Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
|
2012-05-01 01:00:04 +00:00
|
|
|
EXPECT_VALID(result);
|
|
|
|
int64_t elapsed_time = 0;
|
2012-08-06 07:55:53 +00:00
|
|
|
result = Dart_IntegerToInt64(result, &elapsed_time);
|
|
|
|
EXPECT_VALID(result);
|
2012-05-01 01:00:04 +00:00
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:52:52 +00:00
|
|
|
BENCHMARK_SIZE(CoreSnapshotSize) {
|
|
|
|
const char* kScriptChars =
|
|
|
|
"import 'dart:async';\n"
|
|
|
|
"import 'dart:core';\n"
|
|
|
|
"import 'dart:collection';\n"
|
|
|
|
"import 'dart:_internal';\n"
|
|
|
|
"import 'dart:math';\n"
|
|
|
|
"import 'dart:isolate';\n"
|
|
|
|
"import 'dart:mirrors';\n"
|
|
|
|
"import 'dart:typed_data';\n"
|
|
|
|
"\n";
|
|
|
|
|
|
|
|
// Start an Isolate, load a script and create a full snapshot.
|
2014-05-09 18:25:41 +00:00
|
|
|
// Need to load the script into the dart: core library due to
|
|
|
|
// the import of dart:_internal.
|
2019-09-10 23:52:52 +00:00
|
|
|
TestCase::LoadCoreTestScript(kScriptChars, NULL);
|
2013-02-12 02:39:00 +00:00
|
|
|
|
2017-08-08 00:51:21 +00:00
|
|
|
TransitionNativeToVM transition(thread);
|
2018-10-31 19:51:52 +00:00
|
|
|
StackZone zone(thread);
|
|
|
|
|
|
|
|
Api::CheckAndFinalizePendingClasses(thread);
|
|
|
|
|
2013-02-12 02:39:00 +00:00
|
|
|
// Write snapshot with object content.
|
[vm] Consolidate the *WriteStream hierarchy.
All *WriteStream classes are now part of the same hierarchy:
class BaseWriteStream : ValueObject;
Base class for all *WriteStreams. Provides all the methods from
the old WriteStream except for buffer() and SetPosition()
(relegated to NonStreamingWriteStreams). Has one pure virtual
method Realloc that must be overridden by concrete subclasses.
class NonStreamingWriteStream : BaseWriteStream;
Base class for all *WriteStreams where the entire stream is available
at all times (i.e., no flushing to an external sink). Extends the
public BaseWriteStream API with buffer() (for accessing the stream
contents) and SetPosition() (for changing the current stream pointer
to the given absolute position in the stream).
class MallocWriteStream : NonStreamingWriteStream;
Uses realloc to reallocate the internal buffer. Almost the same as
the old WriteStream, except that it only takes an initial size. Adds
one public method Steal() for taking ownership of the current buffer
contents (after which the buffer is reset to an empty state). Instead
of passing a pointer to a buffer, the internal buffer must be accessed
via either Steal() or buffer(), which allows access to the current
stream contents without changing ownership or resetting the stream.
The internal buffer is freed on stream destruction.
class ZoneWriteStream: NonStreamingWriteStream;
Takes a zone and reallocates the internal buffer in that zone. No
additional public methods beyond those available from
NonStreamingWriteStream.
class StreamingWriteStream : BaseWriteStream;
Uses realloc to reallocate the internal buffer. Generally same as
before, where the contents of the stream are periodically flushed
using Dart_StreamingWriteCallback. Since it extends BaseWriteStream,
there are now more methods available for writing data to the stream
than just Print/VPrint/WriteBytes. Since portions of the stream may be
flushed and thus no longer in the internal buffer, does not provide
access to the contents of the stream or a way to reposition the
current stream pointer. Flushes any unflushed data and frees the
internal buffer on stream destruction.
Also refactor things so that write streams are passed to appropriate
recipients, instead of the recipients taking arguments they only used to
create a WriteStream internally. Thus, recipients now can just specify
the appropriate base class for the public API used:
* BaseWriteStream for just writing to the stream, or
* NonStreamingWriteStream if re-positioning or the stream contents are
needed.
Change-Id: I419096ecd9331483d168b079fca55b69ef397f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
|
|
|
MallocWriteStream vm_snapshot_data(FullSnapshotWriter::kInitialSize);
|
|
|
|
MallocWriteStream isolate_snapshot_data(FullSnapshotWriter::kInitialSize);
|
|
|
|
FullSnapshotWriter writer(
|
2020-10-08 19:59:15 +00:00
|
|
|
Snapshot::kFullCore, &vm_snapshot_data, &isolate_snapshot_data,
|
[vm] Consolidate the *WriteStream hierarchy.
All *WriteStream classes are now part of the same hierarchy:
class BaseWriteStream : ValueObject;
Base class for all *WriteStreams. Provides all the methods from
the old WriteStream except for buffer() and SetPosition()
(relegated to NonStreamingWriteStreams). Has one pure virtual
method Realloc that must be overridden by concrete subclasses.
class NonStreamingWriteStream : BaseWriteStream;
Base class for all *WriteStreams where the entire stream is available
at all times (i.e., no flushing to an external sink). Extends the
public BaseWriteStream API with buffer() (for accessing the stream
contents) and SetPosition() (for changing the current stream pointer
to the given absolute position in the stream).
class MallocWriteStream : NonStreamingWriteStream;
Uses realloc to reallocate the internal buffer. Almost the same as
the old WriteStream, except that it only takes an initial size. Adds
one public method Steal() for taking ownership of the current buffer
contents (after which the buffer is reset to an empty state). Instead
of passing a pointer to a buffer, the internal buffer must be accessed
via either Steal() or buffer(), which allows access to the current
stream contents without changing ownership or resetting the stream.
The internal buffer is freed on stream destruction.
class ZoneWriteStream: NonStreamingWriteStream;
Takes a zone and reallocates the internal buffer in that zone. No
additional public methods beyond those available from
NonStreamingWriteStream.
class StreamingWriteStream : BaseWriteStream;
Uses realloc to reallocate the internal buffer. Generally same as
before, where the contents of the stream are periodically flushed
using Dart_StreamingWriteCallback. Since it extends BaseWriteStream,
there are now more methods available for writing data to the stream
than just Print/VPrint/WriteBytes. Since portions of the stream may be
flushed and thus no longer in the internal buffer, does not provide
access to the contents of the stream or a way to reposition the
current stream pointer. Flushes any unflushed data and frees the
internal buffer on stream destruction.
Also refactor things so that write streams are passed to appropriate
recipients, instead of the recipients taking arguments they only used to
create a WriteStream internally. Thus, recipients now can just specify
the appropriate base class for the public API used:
* BaseWriteStream for just writing to the stream, or
* NonStreamingWriteStream if re-positioning or the stream contents are
needed.
Change-Id: I419096ecd9331483d168b079fca55b69ef397f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
|
|
|
/*vm_image_writer=*/nullptr, /*iso_image_writer=*/nullptr);
|
2013-02-12 02:39:00 +00:00
|
|
|
writer.WriteFullSnapshot();
|
2017-01-23 18:25:02 +00:00
|
|
|
const Snapshot* snapshot =
|
[vm] Consolidate the *WriteStream hierarchy.
All *WriteStream classes are now part of the same hierarchy:
class BaseWriteStream : ValueObject;
Base class for all *WriteStreams. Provides all the methods from
the old WriteStream except for buffer() and SetPosition()
(relegated to NonStreamingWriteStreams). Has one pure virtual
method Realloc that must be overridden by concrete subclasses.
class NonStreamingWriteStream : BaseWriteStream;
Base class for all *WriteStreams where the entire stream is available
at all times (i.e., no flushing to an external sink). Extends the
public BaseWriteStream API with buffer() (for accessing the stream
contents) and SetPosition() (for changing the current stream pointer
to the given absolute position in the stream).
class MallocWriteStream : NonStreamingWriteStream;
Uses realloc to reallocate the internal buffer. Almost the same as
the old WriteStream, except that it only takes an initial size. Adds
one public method Steal() for taking ownership of the current buffer
contents (after which the buffer is reset to an empty state). Instead
of passing a pointer to a buffer, the internal buffer must be accessed
via either Steal() or buffer(), which allows access to the current
stream contents without changing ownership or resetting the stream.
The internal buffer is freed on stream destruction.
class ZoneWriteStream: NonStreamingWriteStream;
Takes a zone and reallocates the internal buffer in that zone. No
additional public methods beyond those available from
NonStreamingWriteStream.
class StreamingWriteStream : BaseWriteStream;
Uses realloc to reallocate the internal buffer. Generally same as
before, where the contents of the stream are periodically flushed
using Dart_StreamingWriteCallback. Since it extends BaseWriteStream,
there are now more methods available for writing data to the stream
than just Print/VPrint/WriteBytes. Since portions of the stream may be
flushed and thus no longer in the internal buffer, does not provide
access to the contents of the stream or a way to reposition the
current stream pointer. Flushes any unflushed data and frees the
internal buffer on stream destruction.
Also refactor things so that write streams are passed to appropriate
recipients, instead of the recipients taking arguments they only used to
create a WriteStream internally. Thus, recipients now can just specify
the appropriate base class for the public API used:
* BaseWriteStream for just writing to the stream, or
* NonStreamingWriteStream if re-positioning or the stream contents are
needed.
Change-Id: I419096ecd9331483d168b079fca55b69ef397f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
|
|
|
Snapshot::SetupFromBuffer(isolate_snapshot_data.buffer());
|
2020-10-08 19:59:15 +00:00
|
|
|
ASSERT(snapshot->kind() == Snapshot::kFullCore);
|
2019-09-10 23:52:52 +00:00
|
|
|
benchmark->set_score(snapshot->length());
|
2019-09-06 18:24:19 +00:00
|
|
|
}
|
2017-01-11 19:12:40 +00:00
|
|
|
|
2019-09-06 18:24:19 +00:00
|
|
|
BENCHMARK_SIZE(StandaloneSnapshotSize) {
|
2019-09-10 23:52:52 +00:00
|
|
|
const char* kScriptChars =
|
|
|
|
"import 'dart:async';\n"
|
|
|
|
"import 'dart:core';\n"
|
|
|
|
"import 'dart:collection';\n"
|
|
|
|
"import 'dart:convert';\n"
|
|
|
|
"import 'dart:math';\n"
|
|
|
|
"import 'dart:isolate';\n"
|
|
|
|
"import 'dart:mirrors';\n"
|
|
|
|
"import 'dart:typed_data';\n"
|
|
|
|
"import 'dart:io';\n"
|
|
|
|
"import 'dart:cli';\n"
|
|
|
|
"\n";
|
|
|
|
|
|
|
|
// Start an Isolate, load a script and create a full snapshot.
|
|
|
|
// Need to load the script into the dart: core library due to
|
|
|
|
// the import of dart:_internal.
|
|
|
|
TestCase::LoadCoreTestScript(kScriptChars, NULL);
|
|
|
|
|
|
|
|
TransitionNativeToVM transition(thread);
|
|
|
|
StackZone zone(thread);
|
|
|
|
|
|
|
|
Api::CheckAndFinalizePendingClasses(thread);
|
|
|
|
|
|
|
|
// Write snapshot with object content.
|
[vm] Consolidate the *WriteStream hierarchy.
All *WriteStream classes are now part of the same hierarchy:
class BaseWriteStream : ValueObject;
Base class for all *WriteStreams. Provides all the methods from
the old WriteStream except for buffer() and SetPosition()
(relegated to NonStreamingWriteStreams). Has one pure virtual
method Realloc that must be overridden by concrete subclasses.
class NonStreamingWriteStream : BaseWriteStream;
Base class for all *WriteStreams where the entire stream is available
at all times (i.e., no flushing to an external sink). Extends the
public BaseWriteStream API with buffer() (for accessing the stream
contents) and SetPosition() (for changing the current stream pointer
to the given absolute position in the stream).
class MallocWriteStream : NonStreamingWriteStream;
Uses realloc to reallocate the internal buffer. Almost the same as
the old WriteStream, except that it only takes an initial size. Adds
one public method Steal() for taking ownership of the current buffer
contents (after which the buffer is reset to an empty state). Instead
of passing a pointer to a buffer, the internal buffer must be accessed
via either Steal() or buffer(), which allows access to the current
stream contents without changing ownership or resetting the stream.
The internal buffer is freed on stream destruction.
class ZoneWriteStream: NonStreamingWriteStream;
Takes a zone and reallocates the internal buffer in that zone. No
additional public methods beyond those available from
NonStreamingWriteStream.
class StreamingWriteStream : BaseWriteStream;
Uses realloc to reallocate the internal buffer. Generally same as
before, where the contents of the stream are periodically flushed
using Dart_StreamingWriteCallback. Since it extends BaseWriteStream,
there are now more methods available for writing data to the stream
than just Print/VPrint/WriteBytes. Since portions of the stream may be
flushed and thus no longer in the internal buffer, does not provide
access to the contents of the stream or a way to reposition the
current stream pointer. Flushes any unflushed data and frees the
internal buffer on stream destruction.
Also refactor things so that write streams are passed to appropriate
recipients, instead of the recipients taking arguments they only used to
create a WriteStream internally. Thus, recipients now can just specify
the appropriate base class for the public API used:
* BaseWriteStream for just writing to the stream, or
* NonStreamingWriteStream if re-positioning or the stream contents are
needed.
Change-Id: I419096ecd9331483d168b079fca55b69ef397f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
|
|
|
MallocWriteStream vm_snapshot_data(FullSnapshotWriter::kInitialSize);
|
|
|
|
MallocWriteStream isolate_snapshot_data(FullSnapshotWriter::kInitialSize);
|
|
|
|
FullSnapshotWriter writer(
|
2020-10-08 19:59:15 +00:00
|
|
|
Snapshot::kFullCore, &vm_snapshot_data, &isolate_snapshot_data,
|
[vm] Consolidate the *WriteStream hierarchy.
All *WriteStream classes are now part of the same hierarchy:
class BaseWriteStream : ValueObject;
Base class for all *WriteStreams. Provides all the methods from
the old WriteStream except for buffer() and SetPosition()
(relegated to NonStreamingWriteStreams). Has one pure virtual
method Realloc that must be overridden by concrete subclasses.
class NonStreamingWriteStream : BaseWriteStream;
Base class for all *WriteStreams where the entire stream is available
at all times (i.e., no flushing to an external sink). Extends the
public BaseWriteStream API with buffer() (for accessing the stream
contents) and SetPosition() (for changing the current stream pointer
to the given absolute position in the stream).
class MallocWriteStream : NonStreamingWriteStream;
Uses realloc to reallocate the internal buffer. Almost the same as
the old WriteStream, except that it only takes an initial size. Adds
one public method Steal() for taking ownership of the current buffer
contents (after which the buffer is reset to an empty state). Instead
of passing a pointer to a buffer, the internal buffer must be accessed
via either Steal() or buffer(), which allows access to the current
stream contents without changing ownership or resetting the stream.
The internal buffer is freed on stream destruction.
class ZoneWriteStream: NonStreamingWriteStream;
Takes a zone and reallocates the internal buffer in that zone. No
additional public methods beyond those available from
NonStreamingWriteStream.
class StreamingWriteStream : BaseWriteStream;
Uses realloc to reallocate the internal buffer. Generally same as
before, where the contents of the stream are periodically flushed
using Dart_StreamingWriteCallback. Since it extends BaseWriteStream,
there are now more methods available for writing data to the stream
than just Print/VPrint/WriteBytes. Since portions of the stream may be
flushed and thus no longer in the internal buffer, does not provide
access to the contents of the stream or a way to reposition the
current stream pointer. Flushes any unflushed data and frees the
internal buffer on stream destruction.
Also refactor things so that write streams are passed to appropriate
recipients, instead of the recipients taking arguments they only used to
create a WriteStream internally. Thus, recipients now can just specify
the appropriate base class for the public API used:
* BaseWriteStream for just writing to the stream, or
* NonStreamingWriteStream if re-positioning or the stream contents are
needed.
Change-Id: I419096ecd9331483d168b079fca55b69ef397f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
|
|
|
/*vm_image_writer=*/nullptr, /*iso_image_writer=*/nullptr);
|
2019-09-10 23:52:52 +00:00
|
|
|
writer.WriteFullSnapshot();
|
|
|
|
const Snapshot* snapshot =
|
[vm] Consolidate the *WriteStream hierarchy.
All *WriteStream classes are now part of the same hierarchy:
class BaseWriteStream : ValueObject;
Base class for all *WriteStreams. Provides all the methods from
the old WriteStream except for buffer() and SetPosition()
(relegated to NonStreamingWriteStreams). Has one pure virtual
method Realloc that must be overridden by concrete subclasses.
class NonStreamingWriteStream : BaseWriteStream;
Base class for all *WriteStreams where the entire stream is available
at all times (i.e., no flushing to an external sink). Extends the
public BaseWriteStream API with buffer() (for accessing the stream
contents) and SetPosition() (for changing the current stream pointer
to the given absolute position in the stream).
class MallocWriteStream : NonStreamingWriteStream;
Uses realloc to reallocate the internal buffer. Almost the same as
the old WriteStream, except that it only takes an initial size. Adds
one public method Steal() for taking ownership of the current buffer
contents (after which the buffer is reset to an empty state). Instead
of passing a pointer to a buffer, the internal buffer must be accessed
via either Steal() or buffer(), which allows access to the current
stream contents without changing ownership or resetting the stream.
The internal buffer is freed on stream destruction.
class ZoneWriteStream: NonStreamingWriteStream;
Takes a zone and reallocates the internal buffer in that zone. No
additional public methods beyond those available from
NonStreamingWriteStream.
class StreamingWriteStream : BaseWriteStream;
Uses realloc to reallocate the internal buffer. Generally same as
before, where the contents of the stream are periodically flushed
using Dart_StreamingWriteCallback. Since it extends BaseWriteStream,
there are now more methods available for writing data to the stream
than just Print/VPrint/WriteBytes. Since portions of the stream may be
flushed and thus no longer in the internal buffer, does not provide
access to the contents of the stream or a way to reposition the
current stream pointer. Flushes any unflushed data and frees the
internal buffer on stream destruction.
Also refactor things so that write streams are passed to appropriate
recipients, instead of the recipients taking arguments they only used to
create a WriteStream internally. Thus, recipients now can just specify
the appropriate base class for the public API used:
* BaseWriteStream for just writing to the stream, or
* NonStreamingWriteStream if re-positioning or the stream contents are
needed.
Change-Id: I419096ecd9331483d168b079fca55b69ef397f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
|
|
|
Snapshot::SetupFromBuffer(isolate_snapshot_data.buffer());
|
2020-10-08 19:59:15 +00:00
|
|
|
ASSERT(snapshot->kind() == Snapshot::kFullCore);
|
2019-09-10 23:52:52 +00:00
|
|
|
benchmark->set_score(snapshot->length());
|
2013-02-12 02:39:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 22:06:04 +00:00
|
|
|
BENCHMARK(CreateMirrorSystem) {
|
|
|
|
const char* kScriptChars =
|
|
|
|
"import 'dart:mirrors';\n"
|
|
|
|
"\n"
|
|
|
|
"void benchmark() {\n"
|
|
|
|
" currentMirrorSystem();\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
|
|
|
|
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2013-07-24 22:06:04 +00:00
|
|
|
timer.Start();
|
2018-05-03 17:34:13 +00:00
|
|
|
Dart_Handle result = Dart_Invoke(lib, NewString("benchmark"), 0, NULL);
|
|
|
|
EXPECT_VALID(result);
|
2013-07-24 22:06:04 +00:00
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
2014-02-07 17:43:21 +00:00
|
|
|
BENCHMARK(EnterExitIsolate) {
|
|
|
|
const char* kScriptChars =
|
|
|
|
"import 'dart:core';\n"
|
|
|
|
"\n";
|
|
|
|
const intptr_t kLoopCount = 1000000;
|
|
|
|
TestCase::LoadTestScript(kScriptChars, NULL);
|
2018-10-31 19:51:52 +00:00
|
|
|
{
|
|
|
|
TransitionNativeToVM transition(thread);
|
|
|
|
StackZone zone(thread);
|
|
|
|
Api::CheckAndFinalizePendingClasses(thread);
|
|
|
|
}
|
2014-02-07 17:43:21 +00:00
|
|
|
Dart_Isolate isolate = Dart_CurrentIsolate();
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2014-02-07 17:43:21 +00:00
|
|
|
timer.Start();
|
|
|
|
for (intptr_t i = 0; i < kLoopCount; i++) {
|
|
|
|
Dart_ExitIsolate();
|
|
|
|
Dart_EnterIsolate(isolate);
|
|
|
|
}
|
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
2014-03-19 08:54:06 +00:00
|
|
|
BENCHMARK(SerializeNull) {
|
2017-10-31 15:46:43 +00:00
|
|
|
TransitionNativeToVM transition(thread);
|
2018-10-31 19:51:52 +00:00
|
|
|
StackZone zone(thread);
|
2014-03-19 08:54:06 +00:00
|
|
|
const Object& null_object = Object::Handle();
|
|
|
|
const intptr_t kLoopCount = 1000000;
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2014-03-19 08:54:06 +00:00
|
|
|
timer.Start();
|
|
|
|
for (intptr_t i = 0; i < kLoopCount; i++) {
|
2015-09-02 23:07:48 +00:00
|
|
|
StackZone zone(thread);
|
2021-07-29 16:55:55 +00:00
|
|
|
std::unique_ptr<Message> message =
|
2022-08-19 18:10:15 +00:00
|
|
|
WriteMessage(/* same_group */ false, null_object, ILLEGAL_PORT,
|
|
|
|
Message::kNormalPriority);
|
2014-03-19 08:54:06 +00:00
|
|
|
|
|
|
|
// Read object back from the snapshot.
|
2021-07-29 16:55:55 +00:00
|
|
|
ReadMessage(thread, message.get());
|
2014-03-19 08:54:06 +00:00
|
|
|
}
|
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK(SerializeSmi) {
|
2017-10-31 15:46:43 +00:00
|
|
|
TransitionNativeToVM transition(thread);
|
2018-10-31 19:51:52 +00:00
|
|
|
StackZone zone(thread);
|
2014-03-19 08:54:06 +00:00
|
|
|
const Integer& smi_object = Integer::Handle(Smi::New(42));
|
|
|
|
const intptr_t kLoopCount = 1000000;
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2014-03-19 08:54:06 +00:00
|
|
|
timer.Start();
|
|
|
|
for (intptr_t i = 0; i < kLoopCount; i++) {
|
2015-09-02 23:07:48 +00:00
|
|
|
StackZone zone(thread);
|
2019-05-06 21:01:39 +00:00
|
|
|
std::unique_ptr<Message> message =
|
2022-08-19 18:10:15 +00:00
|
|
|
WriteMessage(/* same_group */ false, smi_object, ILLEGAL_PORT,
|
|
|
|
Message::kNormalPriority);
|
2014-03-19 08:54:06 +00:00
|
|
|
|
|
|
|
// Read object back from the snapshot.
|
2021-07-29 16:55:55 +00:00
|
|
|
ReadMessage(thread, message.get());
|
2014-03-19 08:54:06 +00:00
|
|
|
}
|
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK(SimpleMessage) {
|
2016-02-01 18:57:34 +00:00
|
|
|
TransitionNativeToVM transition(thread);
|
2018-10-31 19:51:52 +00:00
|
|
|
StackZone zone(thread);
|
2014-03-19 08:54:06 +00:00
|
|
|
const Array& array_object = Array::Handle(Array::New(2));
|
|
|
|
array_object.SetAt(0, Integer::Handle(Smi::New(42)));
|
|
|
|
array_object.SetAt(1, Object::Handle());
|
|
|
|
const intptr_t kLoopCount = 1000000;
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2014-03-19 08:54:06 +00:00
|
|
|
timer.Start();
|
|
|
|
for (intptr_t i = 0; i < kLoopCount; i++) {
|
2015-09-02 23:07:48 +00:00
|
|
|
StackZone zone(thread);
|
2022-08-19 18:10:15 +00:00
|
|
|
std::unique_ptr<Message> message =
|
|
|
|
WriteMessage(/* same_group */ false, array_object, ILLEGAL_PORT,
|
|
|
|
Message::kNormalPriority);
|
2014-03-19 08:54:06 +00:00
|
|
|
|
|
|
|
// Read object back from the snapshot.
|
2021-07-29 16:55:55 +00:00
|
|
|
ReadMessage(thread, message.get());
|
2014-03-19 08:54:06 +00:00
|
|
|
}
|
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
2015-05-28 16:32:54 +00:00
|
|
|
BENCHMARK(LargeMap) {
|
|
|
|
const char* kScript =
|
|
|
|
"makeMap() {\n"
|
|
|
|
" Map m = {};\n"
|
|
|
|
" for (int i = 0; i < 100000; ++i) m[i*13+i*(i>>7)] = i;\n"
|
|
|
|
" return m;\n"
|
|
|
|
"}";
|
|
|
|
Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
|
|
|
|
EXPECT_VALID(h_lib);
|
|
|
|
Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL);
|
|
|
|
EXPECT_VALID(h_result);
|
2018-08-28 16:40:17 +00:00
|
|
|
TransitionNativeToVM transition(thread);
|
2018-10-31 19:51:52 +00:00
|
|
|
StackZone zone(thread);
|
2015-05-28 16:32:54 +00:00
|
|
|
Instance& map = Instance::Handle();
|
|
|
|
map ^= Api::UnwrapHandle(h_result);
|
|
|
|
const intptr_t kLoopCount = 100;
|
2021-05-11 11:15:53 +00:00
|
|
|
Timer timer;
|
2015-05-28 16:32:54 +00:00
|
|
|
timer.Start();
|
|
|
|
for (intptr_t i = 0; i < kLoopCount; i++) {
|
2015-09-02 23:07:48 +00:00
|
|
|
StackZone zone(thread);
|
2022-08-19 18:10:15 +00:00
|
|
|
std::unique_ptr<Message> message = WriteMessage(
|
|
|
|
/* same_group */ false, map, ILLEGAL_PORT, Message::kNormalPriority);
|
2015-05-28 16:32:54 +00:00
|
|
|
|
|
|
|
// Read object back from the snapshot.
|
2021-07-29 16:55:55 +00:00
|
|
|
ReadMessage(thread, message.get());
|
2015-05-28 16:32:54 +00:00
|
|
|
}
|
|
|
|
timer.Stop();
|
|
|
|
int64_t elapsed_time = timer.TotalElapsedTime();
|
|
|
|
benchmark->set_score(elapsed_time);
|
|
|
|
}
|
|
|
|
|
2016-09-09 16:47:56 +00:00
|
|
|
BENCHMARK_MEMORY(InitialRSS) {
|
2017-08-15 00:02:22 +00:00
|
|
|
benchmark->set_score(bin::Process::MaxRSS());
|
2016-09-09 16:47:56 +00:00
|
|
|
}
|
|
|
|
|
2012-04-21 01:36:23 +00:00
|
|
|
} // namespace dart
|