v8/test/cctest/test-feedback-vector.h
Leszek Swirski 37680d6563 [objects] Make feedback vector a first-class object
Instead of having feedback vector as a subtype of FixedArray with
reserved slots, make it a first-class variable-sized object with a
fixed-size header. This allows us to compress counters to ints in the
header, rather than forcing them to be Smis.

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Icc5f088ffbc2e2651b845bc71ea42060639e3e48
Reviewed-on: https://chromium-review.googlesource.com/585129
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Michael Stanton <mvstanton@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46935}
2017-07-27 13:31:55 +00:00

60 lines
1.8 KiB
C++

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_TEST_FEEDBACK_VECTOR_H_
#define V8_TEST_FEEDBACK_VECTOR_H_
#include "src/objects.h"
#include "src/objects/shared-function-info.h"
namespace v8 {
namespace internal {
// Helper class that allows to write tests in a slot size independent manner.
// Use helper.slot(X) to get X'th slot identifier.
class FeedbackVectorHelper {
public:
explicit FeedbackVectorHelper(Handle<FeedbackVector> vector)
: vector_(vector) {
int slot_count = vector->length();
slots_.reserve(slot_count);
FeedbackMetadataIterator iter(vector->metadata());
while (iter.HasNext()) {
FeedbackSlot slot = iter.Next();
slots_.push_back(slot);
}
}
Handle<FeedbackVector> vector() { return vector_; }
// Returns slot identifier by numerical index.
FeedbackSlot slot(int index) const { return slots_[index]; }
// Returns the number of slots in the feedback vector.
int slot_count() const { return static_cast<int>(slots_.size()); }
private:
Handle<FeedbackVector> vector_;
std::vector<FeedbackSlot> slots_;
};
template <typename Spec>
Handle<FeedbackVector> NewFeedbackVector(Isolate* isolate, Spec* spec) {
Handle<FeedbackMetadata> metadata = FeedbackMetadata::New(isolate, spec);
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
isolate->factory()->empty_string(), MaybeHandle<Code>(), false);
shared->set_feedback_metadata(*metadata);
return FeedbackVector::New(isolate, shared);
}
template <typename Spec>
Handle<FeedbackMetadata> NewFeedbackMetadata(Isolate* isolate, Spec* spec) {
return FeedbackMetadata::New(isolate, spec);
}
} // namespace internal
} // namespace v8
#endif