45a46ca2b8
Unlikecfc8e6de, this does _not_ replace the default variable length encoding for {Read,Write}Streams, but insteads adds separate {Read,Write}{S,}LEB128 methods to the appropriate classes. If we later find the cause of the issues that led to the revert ofcfc8e6de, it'll be easy to switch over then. Note that WriteLEB128 asserts that the value is non-negative if used with a signed type (since negative values suggests that SLEB128 should be used instead for minimal encoding). Also removes the various other encoding and decoding methods for (S)LEB128 across the codebase and changes those clients to use {Read,Write}Streams instead. Other cleanups: * Various constant-related cleanups in datastream.h. * Adds DART_FORCE_INLINE to ReadStream::ReadByte and uses it in the default variable length decoding methods for retrieving bytes from the stream instead of managing current_ by hand. * Creates a canonical empty CompressedStackMaps instance and uses that instead of the null CompressedStackMaps instance in most cases. The only remaining (expected) use of the null CompressedStackMaps instance is for the global table in the object store when no global table exists (e.g., in JIT mode before any snapshotting). * Moves CompressedStackMapsIterator from code_descriptors.h to an Iterator class within CompressedStackMaps in object.h (similar to PcDescriptors::Iterator), to limit friend declarations and because it conceptually makes more sense as part of CompressedStackMaps. * Removed CompressedStackMaps::PayloadByte, since existing clients (CompressedStackMaps::Iterator, StackMapEntry in program_visitor.cc) are better served by just operating on the payload buffer directly (with appropriate NoSafepointScopes). * WriteStreams no longer allocate their initial space on construction, but rather on the first write, so no allocation is performed by constructing a never-used WriteStream. 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,vm-kernel-ubsan-linux-release-x64-try,vm-kernel-tsan-linux-release-x64-try,vm-kernel-precomp-ubsan-linux-release-x64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-precomp-msan-linux-release-x64-try,vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-msan-linux-release-x64-try,vm-kernel-asan-linux-release-x64-try Change-Id: Ice63321abaa79157fbe9f230a864c8bba0e6dea9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166421 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Tess Strickland <sstrickl@google.com>
135 lines
3.8 KiB
C++
135 lines
3.8 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.
|
|
|
|
#include "vm/bitmap.h"
|
|
|
|
#include "platform/assert.h"
|
|
#include "vm/code_descriptors.h"
|
|
#include "vm/object.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
// 0x4 is just a placeholder PC offset because no entry of a CSM should
|
|
// have a PC offset of 0, otherwise internal assumptions break.
|
|
static const uint32_t kTestPcOffset = 0x4;
|
|
static const intptr_t kTestSpillSlotBitCount = 0;
|
|
|
|
static CompressedStackMapsPtr MapsFromBuilder(Zone* zone, BitmapBuilder* bmap) {
|
|
CompressedStackMapsBuilder builder(zone);
|
|
builder.AddEntry(kTestPcOffset, bmap, kTestSpillSlotBitCount);
|
|
return builder.Finalize();
|
|
}
|
|
|
|
ISOLATE_UNIT_TEST_CASE(BitmapBuilder) {
|
|
// Test basic bit map builder operations.
|
|
BitmapBuilder* builder1 = new BitmapBuilder();
|
|
EXPECT_EQ(0, builder1->Length());
|
|
|
|
bool value = true;
|
|
for (int32_t i = 0; i < 128; i++) {
|
|
builder1->Set(i, value);
|
|
value = !value;
|
|
}
|
|
EXPECT_EQ(128, builder1->Length());
|
|
value = true;
|
|
for (int32_t i = 0; i < 128; i++) {
|
|
EXPECT_EQ(value, builder1->Get(i));
|
|
value = !value;
|
|
}
|
|
value = true;
|
|
for (int32_t i = 0; i < 1024; i++) {
|
|
builder1->Set(i, value);
|
|
value = !value;
|
|
}
|
|
EXPECT_EQ(1024, builder1->Length());
|
|
value = true;
|
|
for (int32_t i = 0; i < 1024; i++) {
|
|
EXPECT_EQ(value, builder1->Get(i));
|
|
value = !value;
|
|
}
|
|
|
|
// Create a CompressedStackMaps object and verify its contents.
|
|
const auto& maps1 = CompressedStackMaps::Handle(
|
|
thread->zone(), MapsFromBuilder(thread->zone(), builder1));
|
|
CompressedStackMaps::Iterator it1(thread, maps1);
|
|
EXPECT(it1.MoveNext());
|
|
|
|
EXPECT_EQ(kTestPcOffset, it1.pc_offset());
|
|
EXPECT_EQ(kTestSpillSlotBitCount, it1.SpillSlotBitCount());
|
|
EXPECT_EQ(1024, it1.Length());
|
|
value = true;
|
|
for (int32_t i = 0; i < 1024; i++) {
|
|
EXPECT_EQ(value, it1.IsObject(i));
|
|
value = !value;
|
|
}
|
|
|
|
EXPECT(!it1.MoveNext());
|
|
|
|
// Test the SetRange function in the builder.
|
|
builder1->SetRange(0, 256, false);
|
|
EXPECT_EQ(1024, builder1->Length());
|
|
builder1->SetRange(257, 1024, true);
|
|
EXPECT_EQ(1025, builder1->Length());
|
|
builder1->SetRange(1025, 2048, false);
|
|
EXPECT_EQ(2049, builder1->Length());
|
|
for (int32_t i = 0; i <= 256; i++) {
|
|
EXPECT(!builder1->Get(i));
|
|
}
|
|
for (int32_t i = 257; i <= 1024; i++) {
|
|
EXPECT(builder1->Get(i));
|
|
}
|
|
for (int32_t i = 1025; i <= 2048; i++) {
|
|
EXPECT(!builder1->Get(i));
|
|
}
|
|
|
|
const auto& maps2 = CompressedStackMaps::Handle(
|
|
thread->zone(), MapsFromBuilder(thread->zone(), builder1));
|
|
CompressedStackMaps::Iterator it2(thread, maps2);
|
|
EXPECT(it2.MoveNext());
|
|
|
|
EXPECT_EQ(kTestPcOffset, it2.pc_offset());
|
|
EXPECT_EQ(kTestSpillSlotBitCount, it2.SpillSlotBitCount());
|
|
EXPECT_EQ(2049, it2.Length());
|
|
for (int32_t i = 0; i <= 256; i++) {
|
|
EXPECT(!it2.IsObject(i));
|
|
}
|
|
for (int32_t i = 257; i <= 1024; i++) {
|
|
EXPECT(it2.IsObject(i));
|
|
}
|
|
for (int32_t i = 1025; i <= 2048; i++) {
|
|
EXPECT(!it2.IsObject(i));
|
|
}
|
|
|
|
EXPECT(!it2.MoveNext());
|
|
|
|
// Test using SetLength to shorten the builder, followed by lengthening.
|
|
builder1->SetLength(747);
|
|
EXPECT_EQ(747, builder1->Length());
|
|
for (int32_t i = 257; i < 747; ++i) {
|
|
EXPECT(builder1->Get(i));
|
|
}
|
|
|
|
builder1->Set(800, false);
|
|
EXPECT_EQ(801, builder1->Length());
|
|
for (int32_t i = 257; i < 747; ++i) {
|
|
EXPECT(builder1->Get(i));
|
|
}
|
|
for (int32_t i = 747; i < 801; ++i) {
|
|
EXPECT(!builder1->Get(i));
|
|
}
|
|
|
|
builder1->Set(900, true);
|
|
EXPECT_EQ(901, builder1->Length());
|
|
for (int32_t i = 257; i < 747; ++i) {
|
|
EXPECT(builder1->Get(i));
|
|
}
|
|
for (int32_t i = 747; i < 900; ++i) {
|
|
EXPECT(!builder1->Get(i));
|
|
}
|
|
EXPECT(builder1->Get(900));
|
|
}
|
|
|
|
} // namespace dart
|