Commit a1cde8fb authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[test] Add more tests for the serializer for background compilation

Add tests for proper serialization of inlinee targets.

Bug: v8:7790
Change-Id: I6bf86de1352f91fddf5f6eba9e889e7d5ac9767c
Reviewed-on: https://chromium-review.googlesource.com/c/1443058
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59193}
parent cb5c1edc
......@@ -2495,7 +2495,7 @@ ObjectRef::ObjectRef(JSHeapBroker* broker, Handle<Object> object)
case JSHeapBroker::kRetired:
UNREACHABLE();
}
CHECK_NOT_NULL(data_);
CHECK_WITH_MSG(data_ != nullptr, "Object is not known to the heap broker");
}
namespace {
......@@ -2690,6 +2690,10 @@ void JSFunctionRef::Serialize() {
data()->AsJSFunction()->Serialize(broker());
}
bool JSFunctionRef::IsSerializedForCompilation() const {
return shared().IsSerializedForCompilation(feedback_vector());
}
void SharedFunctionInfoRef::SetSerializedForCompilation(
FeedbackVectorRef feedback) {
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
......
......@@ -237,6 +237,7 @@ class JSFunctionRef : public JSObjectRef {
bool PrototypeRequiresRuntimeLookup() const;
void Serialize();
bool IsSerializedForCompilation() const;
// The following are available only after calling Serialize().
ObjectRef prototype() const;
......
......@@ -19,20 +19,64 @@ namespace compiler {
SerializerTester::SerializerTester(const char* source)
: canonical_(main_isolate()) {
// The tests only make sense in the context of concurrent compilation.
FLAG_concurrent_inlining = true;
// The tests don't make sense when optimizations are turned off.
FLAG_opt = true;
// We need the IC to feed it to the serializer.
FLAG_use_ic = true;
// We need manual control over when a given function is optimized.
FLAG_always_opt = false;
std::string function_string = "(function() { ";
function_string += source;
function_string += " })();";
Handle<JSFunction> function = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(CompileRun(source))));
*v8::Local<v8::Function>::Cast(CompileRun(function_string.c_str()))));
Optimize(function, main_zone(), main_isolate(), 0, &broker_);
function_ = JSFunctionRef(broker_, function);
}
TEST(SerializeEmptyFunction) {
SerializerTester tester("(function() { function f() {}; return f; })();");
CHECK(tester.function().shared().IsSerializedForCompilation(
tester.function().feedback_vector()));
SerializerTester tester("function f() {}; return f;");
CHECK(tester.function().IsSerializedForCompilation());
}
// This helper function allows for testing weather an inlinee candidate
// was properly serialized. It expects that the top-level function (that is
// run through the SerializerTester) will return its inlinee candidate.
void CheckForSerializedInlinee(const char* source) {
SerializerTester tester(source);
JSFunctionRef f = tester.function();
CHECK(f.IsSerializedForCompilation());
MaybeHandle<Object> g_obj = Execution::Call(
tester.isolate(), tester.function().object(),
tester.isolate()->factory()->undefined_value(), 0, nullptr);
Handle<Object> g;
CHECK(g_obj.ToHandle(&g));
Handle<JSFunction> g_func = Handle<JSFunction>::cast(g);
SharedFunctionInfoRef g_sfi(tester.broker(),
handle(g_func->shared(), tester.isolate()));
FeedbackVectorRef g_fv(tester.broker(),
handle(g_func->feedback_vector(), tester.isolate()));
CHECK(g_sfi.IsSerializedForCompilation(g_fv));
}
TEST(SerializeInlinedClosure) {
CheckForSerializedInlinee(
"function f() {"
" return (function g(){ return g; })();"
"}; f(); return f;");
}
TEST(SerializeInlinedFunction) {
CheckForSerializedInlinee(
"function g() {};"
"function f() {"
" g(); return g;"
"}; f(); return f;");
}
} // namespace compiler
} // namespace internal
......
......@@ -14,11 +14,21 @@ namespace compiler {
class ZoneStats;
// The purpose of this class is to provide testing facility for the
// SerializerForBackgroundCompilation class. On a high-level, it executes the
// following steps:
// 1. Wraps the provided source in an IIFE
// 2. Generates bytecode for the given source
// 3. Runs the bytecode which *must* return a function
// 4. Takes the returned function and optimizes it
// 5. The optimized function is accessible through `function()`
class SerializerTester : public HandleAndZoneScope {
public:
explicit SerializerTester(const char* source);
JSFunctionRef function() const { return function_.value(); }
JSHeapBroker* broker() const { return broker_; }
Isolate* isolate() { return main_isolate(); }
private:
CanonicalHandleScope canonical_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment