Files
sdk/runtime/vm/datastream.cc
T
Tess Strickland 72cfc5c638 [vm] Clean up handling of payload-containing objects.
This CL adds a new PAYLOAD_SIZEOF specification to
runtime_offsets_list.h which defines InstanceSize methods given an
method name to invoke to get the header size (i.e., the size of
the object portion before the payload).

It uses this new specification to create appropriate InstanceSize()
methods for objects written to read-only sections of snapshots,
instead of needing separate size calculations for SIMARM_X64.

It adds more methods to Instructions to avoid special casing for bare
instructions mode. It also removes the special casing for SIMARM_X64,
serializing all read-only objects in the same manner even when not
in a crossword situation.

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-kernel-mac-debug-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-win-release-x64-try
Change-Id: Ie3e4009f4bc03688998c32281e42fa22a255731d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165501
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2020-10-06 07:59:33 +00:00

61 lines
1.9 KiB
C++

// Copyright (c) 2018, 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.
#include "vm/datastream.h"
#include "vm/compiler/runtime_api.h"
#include "vm/zone.h"
namespace dart {
void BaseWriteStream::WriteTargetWord(word value) {
ASSERT(compiler::target::kBitsPerWord == kBitsPerWord ||
Utils::IsAbsoluteUint(compiler::target::kBitsPerWord, value));
WriteFixed(static_cast<compiler::target::word>(value));
}
MallocWriteStream::~MallocWriteStream() {
free(buffer_);
}
void MallocWriteStream::Realloc(intptr_t new_size) {
const intptr_t old_offset = current_ - buffer_;
buffer_ = reinterpret_cast<uint8_t*>(realloc(buffer_, new_size));
capacity_ = buffer_ != nullptr ? new_size : 0;
current_ = buffer_ != nullptr ? buffer_ + old_offset : nullptr;
}
void ZoneWriteStream::Realloc(intptr_t new_size) {
const intptr_t old_offset = current_ - buffer_;
buffer_ = zone_->Realloc(buffer_, capacity_, new_size);
capacity_ = buffer_ != nullptr ? new_size : 0;
current_ = buffer_ != nullptr ? buffer_ + old_offset : nullptr;
}
StreamingWriteStream::~StreamingWriteStream() {
Flush();
free(buffer_);
}
void StreamingWriteStream::Realloc(intptr_t new_size) {
Flush();
// Check whether resetting the internal buffer by flushing gave enough space.
if (new_size <= capacity_) {
return;
}
const intptr_t new_capacity = Utils::RoundUp(new_size, 64 * KB);
buffer_ = reinterpret_cast<uint8_t*>(realloc(buffer_, new_capacity));
capacity_ = buffer_ != nullptr ? new_capacity : 0;
current_ = buffer_; // Flushing reset the internal buffer offset to 0.
}
void StreamingWriteStream::Flush() {
intptr_t size = current_ - buffer_;
callback_(callback_data_, buffer_, size);
flushed_size_ += size;
current_ = buffer_;
}
} // namespace dart