Skip to content

Commit

Permalink
[vm, snapshot] Use data image pages for kFull snapshots.
Browse files Browse the repository at this point in the history
 - Enables writing bytecode's PcDescriptors on when IA32 writes app snapshots.
 - Breaks word-size portability of kFull snapshots.

Change-Id: I896d104260593b146ad15e1845e391ae765e60e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115341
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
  • Loading branch information
rmacnak-google authored and commit-bot@chromium.org committed Sep 6, 2019
1 parent add83ad commit c8f3f13
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 301 deletions.
10 changes: 7 additions & 3 deletions runtime/tools/bin_to_coff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# 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.

# See also "PE Format" at https://docs.microsoft.com/en-us/windows/win32/debug/pe-format

import argparse
from ctypes import create_string_buffer
from struct import *
Expand All @@ -19,6 +21,7 @@
SECTION_HEADER_TEXT = 0x20 # Contains executable code
SECTION_HEADER_DATA = 0x40 # Contains only initialized data
SECTION_HEADER_BSS = 0x80 # Contains uninitialized data
SECTION_HEADER_ALIGN_32BYTES = 0x600000

# FILE HEADER FORMAT
# typedef struct {
Expand Down Expand Up @@ -176,17 +179,18 @@ def main():
offset += FILE_HEADER_SIZE

section_name = SECTION_NAME_RODATA
section_type = SECTION_HEADER_DATA
section_flags = SECTION_HEADER_DATA
if args.executable:
section_name = SECTION_NAME_TEXT
section_type = SECTION_HEADER_TEXT
section_flags = SECTION_HEADER_TEXT
section_flags |= SECTION_HEADER_ALIGN_32BYTES

# Populate the section header for a single section.
pack_into(SECTION_HEADER_FORMAT, buff, offset, section_name, SECTION_PADDR,
SECTION_VADDR, section_size + size_symbol_size,
SECTION_RAW_DATA_PTR, SECTION_RELOCATION_PTR,
SECTION_LINE_NUMS_PTR, SECTION_NUM_RELOCATION,
SECTION_NUM_LINE_NUMS, section_type)
SECTION_NUM_LINE_NUMS, section_flags)
offset += SECTION_HEADER_SIZE

# Copy the binary data.
Expand Down
102 changes: 47 additions & 55 deletions runtime/vm/benchmark_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,84 +511,76 @@ static uint8_t* malloc_allocator(uint8_t* ptr,
return reinterpret_cast<uint8_t*>(realloc(ptr, new_size));
}

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.
uint8_t* vm_snapshot_data_buffer;
uint8_t* isolate_snapshot_data_buffer;
// Start an Isolate, load a script and create a full snapshot.
static void BenchmarkSnapshotSize(Benchmark* benchmark, const char* script) {
// Need to load the script into the dart: core library due to
// the import of dart:_internal.
TestCase::LoadCoreTestScript(kScriptChars, NULL);
TestCase::LoadCoreTestScript(script, nullptr);

Thread* thread = Thread::Current();
TransitionNativeToVM transition(thread);
StackZone zone(thread);
HANDLESCOPE(thread);

Api::CheckAndFinalizePendingClasses(thread);

// Write snapshot with object content.
uint8_t* vm_snapshot_data_buffer = nullptr;
uint8_t* isolate_snapshot_data_buffer = nullptr;
uint8_t* vm_snapshot_text_buffer = nullptr;
uint8_t* isolate_snapshot_text_buffer = nullptr;
BlobImageWriter vm_image_writer(thread, &vm_snapshot_text_buffer,
&malloc_allocator, 2 * MB /* initial_size */,
/*shared_objects=*/nullptr,
/*shared_instructions=*/nullptr,
/*reused_instructions=*/nullptr);
BlobImageWriter isolate_image_writer(thread, &isolate_snapshot_text_buffer,
&malloc_allocator,
2 * MB /* initial_size */,
/*shared_objects=*/nullptr,
/*shared_instructions=*/nullptr,
/*reused_instructions=*/nullptr);
FullSnapshotWriter writer(Snapshot::kFull, &vm_snapshot_data_buffer,
&isolate_snapshot_data_buffer, &malloc_allocator,
NULL, NULL /* image_writer */);
&vm_image_writer, &isolate_image_writer);
writer.WriteFullSnapshot();
const Snapshot* snapshot =
Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer);
ASSERT(snapshot->kind() == Snapshot::kFull);
benchmark->set_score(snapshot->length());

free(vm_snapshot_data_buffer);
free(vm_snapshot_text_buffer);
free(isolate_snapshot_data_buffer);
free(isolate_snapshot_text_buffer);
}

BENCHMARK_SIZE(StandaloneSnapshotSize) {
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.
uint8_t* vm_snapshot_data_buffer;
uint8_t* isolate_snapshot_data_buffer;
// 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);
HANDLESCOPE(thread);

Api::CheckAndFinalizePendingClasses(thread);

// Write snapshot with object content.
FullSnapshotWriter writer(Snapshot::kFull, &vm_snapshot_data_buffer,
&isolate_snapshot_data_buffer, &malloc_allocator,
NULL, NULL /* image_writer */);
writer.WriteFullSnapshot();
const Snapshot* snapshot =
Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer);
ASSERT(snapshot->kind() == Snapshot::kFull);
benchmark->set_score(snapshot->length());
BENCHMARK_SIZE(CoreSnapshotSize) {
BenchmarkSnapshotSize(benchmark,
"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");
}

free(vm_snapshot_data_buffer);
free(isolate_snapshot_data_buffer);
BENCHMARK_SIZE(StandaloneSnapshotSize) {
BenchmarkSnapshotSize(benchmark,
"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");
}

BENCHMARK(CreateMirrorSystem) {
Expand Down
Loading

0 comments on commit c8f3f13

Please sign in to comment.