Commit 636d05a9 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[cctest] Improve test coverage for calls to embedded builtins

This adds two tests that generate calls to embedded builtins, one test
inlines the trampoline, and the other uses an indirect load from the
roots array.

Bug: v8:6666, v8:7997
Change-Id: I077f4e9ed311021edb8ee74db625ebb048fdf66b
Reviewed-on: https://chromium-review.googlesource.com/1160237
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54869}
parent 0fda189d
...@@ -25,7 +25,6 @@ TurboAssemblerBase::TurboAssemblerBase(Isolate* isolate, ...@@ -25,7 +25,6 @@ TurboAssemblerBase::TurboAssemblerBase(Isolate* isolate,
void TurboAssemblerBase::IndirectLoadConstant(Register destination, void TurboAssemblerBase::IndirectLoadConstant(Register destination,
Handle<HeapObject> object) { Handle<HeapObject> object) {
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_); CHECK(root_array_available_);
// Before falling back to the (fairly slow) lookup from the constants table, // Before falling back to the (fairly slow) lookup from the constants table,
...@@ -47,6 +46,7 @@ void TurboAssemblerBase::IndirectLoadConstant(Register destination, ...@@ -47,6 +46,7 @@ void TurboAssemblerBase::IndirectLoadConstant(Register destination,
LoadRootRelative(destination, LoadRootRelative(destination,
RootRegisterOffsetForBuiltinIndex(maybe_builtin_index_)); RootRegisterOffsetForBuiltinIndex(maybe_builtin_index_));
} else { } else {
CHECK(isolate()->ShouldLoadConstantsFromRootList());
// Ensure the given object is in the builtins constants table and fetch its // Ensure the given object is in the builtins constants table and fetch its
// index. // index.
BuiltinsConstantsTableBuilder* builder = BuiltinsConstantsTableBuilder* builder =
...@@ -60,7 +60,6 @@ void TurboAssemblerBase::IndirectLoadConstant(Register destination, ...@@ -60,7 +60,6 @@ void TurboAssemblerBase::IndirectLoadConstant(Register destination,
void TurboAssemblerBase::IndirectLoadExternalReference( void TurboAssemblerBase::IndirectLoadExternalReference(
Register destination, ExternalReference reference) { Register destination, ExternalReference reference) {
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_); CHECK(root_array_available_);
if (IsAddressableThroughRootRegister(isolate(), reference)) { if (IsAddressableThroughRootRegister(isolate(), reference)) {
......
...@@ -60,6 +60,10 @@ class CodeAssemblerTester { ...@@ -60,6 +60,10 @@ class CodeAssemblerTester {
&state_, AssemblerOptions::Default(scope_.isolate())); &state_, AssemblerOptions::Default(scope_.isolate()));
} }
Handle<Code> GenerateCode(const AssemblerOptions& options) {
return CodeAssembler::GenerateCode(&state_, options);
}
Handle<Code> GenerateCodeCloseAndEscape() { Handle<Code> GenerateCodeCloseAndEscape() {
return scope_.CloseAndEscape(GenerateCode()); return scope_.CloseAndEscape(GenerateCode());
} }
......
...@@ -3453,6 +3453,54 @@ TEST(IsDoubleElementsKind) { ...@@ -3453,6 +3453,54 @@ TEST(IsDoubleElementsKind) {
0); 0);
} }
TEST(TestCallBuiltinInlineTrampoline) {
Isolate* isolate(CcTest::InitIsolateOnce());
const int kNumParams = 1;
CodeAssemblerTester asm_tester(isolate, kNumParams);
CodeStubAssembler m(asm_tester.state());
const int kContextOffset = 2;
Node* str = m.Parameter(0);
Node* context = m.Parameter(kNumParams + kContextOffset);
Node* index = m.SmiConstant(2);
m.Return(m.CallStub(Builtins::CallableFor(isolate, Builtins::kStringRepeat),
context, str, index));
AssemblerOptions options = AssemblerOptions::Default(isolate);
options.inline_offheap_trampolines = true;
options.use_pc_relative_calls_and_jumps = false;
options.isolate_independent_code = false;
FunctionTester ft(asm_tester.GenerateCode(options), kNumParams);
MaybeHandle<Object> result = ft.Call(MakeString("abcdef"));
CHECK(String::Equals(isolate, MakeString("abcdefabcdef"),
Handle<String>::cast(result.ToHandleChecked())));
}
TEST(TestCallBuiltinIndirectLoad) {
Isolate* isolate(CcTest::InitIsolateOnce());
const int kNumParams = 1;
CodeAssemblerTester asm_tester(isolate, kNumParams);
CodeStubAssembler m(asm_tester.state());
const int kContextOffset = 2;
Node* str = m.Parameter(0);
Node* context = m.Parameter(kNumParams + kContextOffset);
Node* index = m.SmiConstant(2);
m.Return(m.CallStub(Builtins::CallableFor(isolate, Builtins::kStringRepeat),
context, str, index));
AssemblerOptions options = AssemblerOptions::Default(isolate);
options.inline_offheap_trampolines = false;
options.use_pc_relative_calls_and_jumps = false;
options.isolate_independent_code = true;
FunctionTester ft(asm_tester.GenerateCode(options), kNumParams);
MaybeHandle<Object> result = ft.Call(MakeString("abcdef"));
CHECK(String::Equals(isolate, MakeString("abcdefabcdef"),
Handle<String>::cast(result.ToHandleChecked())));
}
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
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