Files
sdk/runtime/vm/snapshot.h
Ryan Macnak d36adbacaf [vm] Remove the VM isolate.
The former contents of the VM isolate are now included into each isolate group. This makes each isolate group's heap independent, and in particular allows each heap to be allocated to a separate pointer cage (not done in this CL).

The duplicated stubs that allowed PC relative calls are removed, since the originals can now be the target of PC relative calls.

The bootstrapping needing to load an AppJIT or AppAOT snapshot is reduced to allocating the oddballs. The code is entirely dropped in the AOT runtime, but the JIT runtime still has it to allow for flags to affect the compilation of the stub code. Further refactoring might be able to remove this for the JIT runtime too, with only gen_snapshot knowing how to bootstrap.

Class serialization no longer distinguishes predefined classes.

The page containing null is marked as never-evacuate. null, false and true must not move because the compiler relies on their low bits having certain patterns for some optimizations. (Previously, the entire VM isolate heap never moved.)

Compaction is disabled for IA32. Due to register pressure, some stub calls must not use a scratch register and embed the address of Code.

The page containing the call-through-safepoint stub is frozen when running with --write-protect-code and the stub is created at runtime (instead of loaded from an AppJIT or AppAOT snapshot). This stub must remain executable even during a safepoint, as a foreign call might during return during a safepoint and only block after the stub directs it to the runtime.

The snapshot symbols are renamed to kDartSnapshotData and kDartSnapshotText. There is no need to distinguish the VM isolate's snapshot, and snaphots are per isolate group not per isolate. Aliases with the old names are added to ease migration.

Some global flags that were automatically set based on the VM isolate's snapshot are now isolate group flags and automatically set by the isolate group's snapshot.

TEST=ci
Change-Id: Iee82016057d609112e9b021d178fc3d4d18b5044
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500621
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-18 11:35:03 -07:00

124 lines
3.7 KiB
C++

// 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.
#ifndef RUNTIME_VM_SNAPSHOT_H_
#define RUNTIME_VM_SNAPSHOT_H_
#include <memory>
#include <utility>
#include "platform/assert.h"
#include "platform/unaligned.h"
#include "vm/allocation.h"
#include "vm/globals.h"
#include "vm/message.h"
#include "vm/thread.h"
namespace dart {
// Structure capturing the raw snapshot.
//
class Snapshot {
public:
enum Kind {
kFull, // Full
kFullJIT, // Full + JIT code
kFullAOT, // Full + AOT code
kModule, // Module snapshot with code.
kInvalid
};
static const char* KindToCString(Kind kind);
static const Snapshot* SetupFromBuffer(const void* raw_memory);
static constexpr int32_t kMagicValue = 0xdcdcf5f5;
static constexpr intptr_t kMagicOffset = 0;
static constexpr intptr_t kMagicSize = sizeof(int32_t);
static constexpr intptr_t kLengthOffset = kMagicOffset + kMagicSize;
static constexpr intptr_t kLengthSize = sizeof(int64_t);
static constexpr intptr_t kKindOffset = kLengthOffset + kLengthSize;
static constexpr intptr_t kKindSize = sizeof(int64_t);
static constexpr intptr_t kHeaderSize = kKindOffset + kKindSize;
// Accessors.
bool check_magic() const {
return Read<int32_t>(kMagicOffset) == kMagicValue;
}
void set_magic() { return Write<int32_t>(kMagicOffset, kMagicValue); }
// Excluding the magic value from the size written in the buffer is needed
// so we give a proper version mismatch error for snapshots create before
// magic value was written by the VM instead of the embedder.
int64_t large_length() const {
return Read<int64_t>(kLengthOffset) + kMagicSize;
}
intptr_t length() const { return static_cast<intptr_t>(large_length()); }
void set_length(intptr_t value) {
return Write<int64_t>(kLengthOffset, value - kMagicSize);
}
Kind kind() const { return static_cast<Kind>(Read<int64_t>(kKindOffset)); }
void set_kind(Kind value) { return Write<int64_t>(kKindOffset, value); }
static bool IsFull(Kind kind) {
return (kind == kFull) || (kind == kFullJIT) || (kind == kFullAOT);
}
static bool IncludesCode(Kind kind) {
return (kind == kFullJIT) || (kind == kFullAOT) || (kind == kModule);
}
static bool IncludesStringsInROData(Kind kind) {
#if !defined(DART_COMPRESSED_POINTERS)
return IncludesCode(kind);
#else
return false;
#endif
}
const uint8_t* Addr() const { return reinterpret_cast<const uint8_t*>(this); }
const uint8_t* DataImage() const {
if (!IncludesCode(kind())) {
return nullptr;
}
uword offset = Utils::RoundUp(length(), kObjectStartAlignment);
return Addr() + offset;
}
private:
// Prevent Snapshot from ever being allocated directly.
Snapshot();
template <typename T>
T Read(intptr_t offset) const {
return LoadUnaligned(
reinterpret_cast<const T*>(reinterpret_cast<uword>(this) + offset));
}
template <typename T>
void Write(intptr_t offset, T value) {
return StoreUnaligned(
reinterpret_cast<T*>(reinterpret_cast<uword>(this) + offset), value);
}
DISALLOW_COPY_AND_ASSIGN(Snapshot);
};
class SerializedObjectBuffer : public StackResource {
public:
SerializedObjectBuffer()
: StackResource(Thread::Current()), message_(nullptr) {}
void set_message(std::unique_ptr<Message> message) {
ASSERT(message_ == nullptr);
message_ = std::move(message);
}
std::unique_ptr<Message> StealMessage() { return std::move(message_); }
private:
std::unique_ptr<Message> message_;
};
} // namespace dart
#endif // RUNTIME_VM_SNAPSHOT_H_