2015-10-01 13:48:05 +00:00
|
|
|
// 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"
|
2017-05-29 13:24:32 +00:00
|
|
|
#include "src/objects/shared-function-info.h"
|
2015-10-01 13:48:05 +00:00
|
|
|
|
|
|
|
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:
|
2017-02-07 14:05:02 +00:00
|
|
|
explicit FeedbackVectorHelper(Handle<FeedbackVector> vector)
|
2015-10-01 13:48:05 +00:00
|
|
|
: vector_(vector) {
|
2017-07-27 12:45:00 +00:00
|
|
|
int slot_count = vector->length();
|
2015-10-01 13:48:05 +00:00
|
|
|
slots_.reserve(slot_count);
|
2017-02-07 14:05:02 +00:00
|
|
|
FeedbackMetadataIterator iter(vector->metadata());
|
2015-10-01 13:48:05 +00:00
|
|
|
while (iter.HasNext()) {
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot = iter.Next();
|
2015-10-01 13:48:05 +00:00
|
|
|
slots_.push_back(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> vector() { return vector_; }
|
2015-10-01 13:48:05 +00:00
|
|
|
|
|
|
|
// Returns slot identifier by numerical index.
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot(int index) const { return slots_[index]; }
|
2015-10-01 13:48:05 +00:00
|
|
|
|
|
|
|
// Returns the number of slots in the feedback vector.
|
|
|
|
int slot_count() const { return static_cast<int>(slots_.size()); }
|
|
|
|
|
|
|
|
private:
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> vector_;
|
2017-02-07 15:19:35 +00:00
|
|
|
std::vector<FeedbackSlot> slots_;
|
2015-10-01 13:48:05 +00:00
|
|
|
};
|
|
|
|
|
2015-10-07 10:33:22 +00:00
|
|
|
template <typename Spec>
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> NewFeedbackVector(Isolate* isolate, Spec* spec) {
|
|
|
|
Handle<FeedbackMetadata> metadata = FeedbackMetadata::New(isolate, spec);
|
2017-02-08 08:33:33 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
|
|
|
|
isolate->factory()->empty_string(), MaybeHandle<Code>(), false);
|
|
|
|
shared->set_feedback_metadata(*metadata);
|
|
|
|
return FeedbackVector::New(isolate, shared);
|
2015-10-07 10:33:22 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 10:03:00 +00:00
|
|
|
template <typename Spec>
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackMetadata> NewFeedbackMetadata(Isolate* isolate, Spec* spec) {
|
|
|
|
return FeedbackMetadata::New(isolate, spec);
|
2017-01-26 10:03:00 +00:00
|
|
|
}
|
2015-10-07 10:33:22 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif
|