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_
|
|
|
|
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/feedback-vector.h"
|
|
|
|
#include "src/objects/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);
|
2018-03-22 16:09:55 +00:00
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
isolate->factory()->NewSharedFunctionInfoForBuiltin(
|
2018-03-23 14:24:03 +00:00
|
|
|
isolate->factory()->empty_string(), Builtins::kIllegal);
|
2018-04-06 11:49:15 +00:00
|
|
|
// Set the raw feedback metadata to circumvent checks that we are not
|
|
|
|
// overwriting existing metadata.
|
|
|
|
shared->set_raw_outer_scope_info_or_feedback_metadata(*metadata);
|
2019-03-25 15:05:47 +00:00
|
|
|
Handle<ClosureFeedbackCellArray> closure_feedback_cell_array =
|
|
|
|
ClosureFeedbackCellArray::New(isolate, shared);
|
2020-07-06 13:43:56 +00:00
|
|
|
IsCompiledScope is_compiled_scope(shared->is_compiled_scope(isolate));
|
2020-06-03 11:14:02 +00:00
|
|
|
return FeedbackVector::New(isolate, shared, closure_feedback_cell_array,
|
|
|
|
&is_compiled_scope);
|
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
|