Commit d4c3c1a5 authored by Thibaud Michaud's avatar Thibaud Michaud Committed by V8 LUCI CQ

[cctest][wasm] Ensure FLAG_stack_size has an effect

Some cctests set the FLAG_stack_size in the TEST() macro which is run
after the cctest runner initializes the main isolate. The flag is only
used during isolate initialization, so this did not have any effect.

This fixes it by using the UNINITIALIZED_TEST() macro, creating the
isolate after setting the flag and passing it through to the WasmRunner.

See also https://crrev.com/c/2862778 which fixes JS cctests.

R=jkummerow@chromium.org

Change-Id: I46df22b80a283d93c48c1dbd250eb3e4ea5ad4a0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2865749
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74331}
parent ccbfa918
......@@ -245,8 +245,8 @@ class V8_NODISCARD InitializedHandleScopeImpl {
i::HandleScope handle_scope_;
};
InitializedHandleScope::InitializedHandleScope()
: main_isolate_(CcTest::InitIsolateOnce()),
InitializedHandleScope::InitializedHandleScope(i::Isolate* isolate)
: main_isolate_(isolate ? isolate : CcTest::InitIsolateOnce()),
initialized_handle_scope_impl_(
new InitializedHandleScopeImpl(main_isolate_)) {}
......
......@@ -619,7 +619,7 @@ class InitializedHandleScopeImpl;
class V8_NODISCARD InitializedHandleScope {
public:
InitializedHandleScope();
explicit InitializedHandleScope(i::Isolate* isolate = nullptr);
~InitializedHandleScope();
// Prefixing the below with main_ reduces a lot of naming clashes.
......
......@@ -2421,18 +2421,47 @@ WASM_EXEC_TEST(Regular_Factorial) {
}
}
namespace {
// TODO(cleanup): Define in cctest.h and re-use where appropriate.
class IsolateScope {
public:
IsolateScope() {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
isolate_ = v8::Isolate::New(create_params);
isolate_->Enter();
}
~IsolateScope() {
isolate_->Exit();
isolate_->Dispose();
}
v8::Isolate* isolate() { return isolate_; }
Isolate* i_isolate() { return reinterpret_cast<Isolate*>(isolate_); }
private:
v8::Isolate* isolate_;
};
} // namespace
// Tail-recursive variation on factorial:
// fact(N) => f(N,1).
//
// f(N,X) where N=<1 => X
// f(N,X) => f(N-1,X*N).
WASM_EXEC_TEST(ReturnCall_Factorial) {
UNINITIALIZED_WASM_EXEC_TEST(ReturnCall_Factorial) {
EXPERIMENTAL_FLAG_SCOPE(return_call);
// Run in bounded amount of stack - 8kb.
FlagScope<int32_t> stack_size(&v8::internal::FLAG_stack_size, 8);
WasmRunner<uint32_t, uint32_t> r(execution_tier);
IsolateScope isolate_scope;
LocalContext current(isolate_scope.isolate());
WasmRunner<uint32_t, uint32_t> r(execution_tier, nullptr, "main",
kRuntimeExceptionSupport,
isolate_scope.i_isolate());
WasmFunctionCompiler& fact_aux_fn =
r.NewFunction<uint32_t, uint32_t, uint32_t>("fact_aux");
......@@ -2460,12 +2489,17 @@ WASM_EXEC_TEST(ReturnCall_Factorial) {
// g(X,0) => X.
// g(X,N) => f(N-1,X*N).
WASM_EXEC_TEST(ReturnCall_MutualFactorial) {
UNINITIALIZED_WASM_EXEC_TEST(ReturnCall_MutualFactorial) {
EXPERIMENTAL_FLAG_SCOPE(return_call);
// Run in bounded amount of stack - 8kb.
FlagScope<int32_t> stack_size(&v8::internal::FLAG_stack_size, 8);
WasmRunner<uint32_t, uint32_t> r(execution_tier);
IsolateScope isolate_scope;
LocalContext current(isolate_scope.isolate());
WasmRunner<uint32_t, uint32_t> r(execution_tier, nullptr, "main",
kRuntimeExceptionSupport,
isolate_scope.i_isolate());
WasmFunctionCompiler& f_fn = r.NewFunction<uint32_t, uint32_t, uint32_t>("f");
WasmFunctionCompiler& g_fn = r.NewFunction<uint32_t, uint32_t, uint32_t>("g");
......@@ -2502,12 +2536,17 @@ WASM_EXEC_TEST(ReturnCall_MutualFactorial) {
// f(N,X,_) where N=<1 => X
// f(N,X,F) => F(N-1,X*N,F).
WASM_EXEC_TEST(ReturnCall_IndirectFactorial) {
UNINITIALIZED_WASM_EXEC_TEST(ReturnCall_IndirectFactorial) {
EXPERIMENTAL_FLAG_SCOPE(return_call);
// Run in bounded amount of stack - 8kb.
FlagScope<int32_t> stack_size(&v8::internal::FLAG_stack_size, 8);
WasmRunner<uint32_t, uint32_t> r(execution_tier);
IsolateScope isolate_scope;
LocalContext current(isolate_scope.isolate());
WasmRunner<uint32_t, uint32_t> r(execution_tier, nullptr, "main",
kRuntimeExceptionSupport,
isolate_scope.i_isolate());
TestSignatures sigs;
......@@ -2546,12 +2585,17 @@ WASM_EXEC_TEST(ReturnCall_IndirectFactorial) {
// sum(N,k) where N<1 =>k.
// sum(N,k) => sum(N-1,k+N).
WASM_EXEC_TEST(ReturnCall_Sum) {
UNINITIALIZED_WASM_EXEC_TEST(ReturnCall_Sum) {
EXPERIMENTAL_FLAG_SCOPE(return_call);
// Run in bounded amount of stack - 8kb.
FlagScope<int32_t> stack_size(&v8::internal::FLAG_stack_size, 8);
WasmRunner<int32_t, int32_t> r(execution_tier);
IsolateScope isolate_scope;
LocalContext current(isolate_scope.isolate());
WasmRunner<int32_t, int32_t> r(execution_tier, nullptr, "main",
kRuntimeExceptionSupport,
isolate_scope.i_isolate());
TestSignatures sigs;
WasmFunctionCompiler& sum_aux_fn = r.NewFunction(sigs.i_ii(), "sum_aux");
......@@ -2583,12 +2627,17 @@ WASM_EXEC_TEST(ReturnCall_Sum) {
// b3(N,_,_,k) where N<1 =>k.
// b3(N,_,_,k) => b1(N-1,k+N).
WASM_EXEC_TEST(ReturnCall_Bounce_Sum) {
UNINITIALIZED_WASM_EXEC_TEST(ReturnCall_Bounce_Sum) {
EXPERIMENTAL_FLAG_SCOPE(return_call);
// Run in bounded amount of stack - 8kb.
FlagScope<int32_t> stack_size(&v8::internal::FLAG_stack_size, 8);
WasmRunner<int32_t, int32_t> r(execution_tier);
IsolateScope isolate_scope;
LocalContext current(isolate_scope.isolate());
WasmRunner<int32_t, int32_t> r(execution_tier, nullptr, "main",
kRuntimeExceptionSupport,
isolate_scope.i_isolate());
TestSignatures sigs;
WasmFunctionCompiler& b1_fn = r.NewFunction(sigs.i_ii(), "b1");
......
......@@ -21,9 +21,10 @@ namespace wasm {
TestingModuleBuilder::TestingModuleBuilder(
Zone* zone, ManuallyImportedJSFunction* maybe_import,
TestExecutionTier tier, RuntimeExceptionSupport exception_support)
TestExecutionTier tier, RuntimeExceptionSupport exception_support,
Isolate* isolate)
: test_module_(std::make_shared<WasmModule>()),
isolate_(CcTest::InitIsolateOnce()),
isolate_(isolate ? isolate : CcTest::InitIsolateOnce()),
enabled_features_(WasmFeatures::FromIsolate(isolate_)),
execution_tier_(tier),
runtime_exception_support_(exception_support) {
......@@ -460,11 +461,9 @@ void WasmFunctionWrapper::Init(CallDescriptor* call_descriptor,
graph()->SetEnd(graph()->NewNode(common()->End(1), r));
}
Handle<Code> WasmFunctionWrapper::GetWrapperCode() {
Handle<Code> WasmFunctionWrapper::GetWrapperCode(Isolate* isolate) {
Handle<Code> code;
if (!code_.ToHandle(&code)) {
Isolate* isolate = CcTest::InitIsolateOnce();
auto call_descriptor = compiler::Linkage::GetSimplifiedCDescriptor(
zone(), signature_, CallDescriptor::kInitializeRootRegister);
......
......@@ -98,7 +98,7 @@ struct ManuallyImportedJSFunction {
class TestingModuleBuilder {
public:
TestingModuleBuilder(Zone*, ManuallyImportedJSFunction*, TestExecutionTier,
RuntimeExceptionSupport);
RuntimeExceptionSupport, Isolate* isolate = nullptr);
~TestingModuleBuilder();
void ChangeOriginToAsmjs() { test_module_->origin = kAsmJsSloppyOrigin; }
......@@ -323,7 +323,7 @@ class WasmFunctionWrapper : private compiler::GraphAndBuilders {
common()->HeapConstant(instance));
}
Handle<Code> GetWrapperCode();
Handle<Code> GetWrapperCode(Isolate* isolate = nullptr);
Signature<MachineType>* signature() const { return signature_; }
......@@ -384,10 +384,12 @@ class WasmRunnerBase : public InitializedHandleScope {
public:
WasmRunnerBase(ManuallyImportedJSFunction* maybe_import,
TestExecutionTier execution_tier, int num_params,
RuntimeExceptionSupport runtime_exception_support)
: zone_(&allocator_, ZONE_NAME, kCompressGraphZone),
RuntimeExceptionSupport runtime_exception_support,
Isolate* isolate = nullptr)
: InitializedHandleScope(isolate),
zone_(&allocator_, ZONE_NAME, kCompressGraphZone),
builder_(&zone_, maybe_import, execution_tier,
runtime_exception_support),
runtime_exception_support, isolate),
wrapper_(&zone_, num_params) {}
static void SetUpTrapCallback() {
......@@ -491,7 +493,9 @@ class WasmRunnerBase : public InitializedHandleScope {
}
}
Handle<Code> GetWrapperCode() { return wrapper_.GetWrapperCode(); }
Handle<Code> GetWrapperCode() {
return wrapper_.GetWrapperCode(main_isolate());
}
private:
static FunctionSig* CreateSig(Zone* zone, MachineType return_type,
......@@ -546,9 +550,10 @@ class WasmRunner : public WasmRunnerBase {
ManuallyImportedJSFunction* maybe_import = nullptr,
const char* main_fn_name = "main",
RuntimeExceptionSupport runtime_exception_support =
kNoRuntimeExceptionSupport)
kNoRuntimeExceptionSupport,
Isolate* isolate = nullptr)
: WasmRunnerBase(maybe_import, execution_tier, sizeof...(ParamTypes),
runtime_exception_support) {
runtime_exception_support, isolate) {
WasmFunctionCompiler& main_fn =
NewFunction<ReturnType, ParamTypes...>(main_fn_name);
// Non-zero if there is an import.
......@@ -560,10 +565,9 @@ class WasmRunner : public WasmRunnerBase {
}
ReturnType Call(ParamTypes... p) {
Isolate* isolate = CcTest::InitIsolateOnce();
// Save the original context, because CEntry (for runtime calls) will
// reset / invalidate it when returning.
SaveContext save_context(isolate);
SaveContext save_context(main_isolate());
DCHECK(compiled_);
if (interpret()) return CallInterpreter(p...);
......@@ -573,9 +577,9 @@ class WasmRunner : public WasmRunnerBase {
wrapper_.SetInnerCode(builder_.GetFunctionCode(main_fn_index_));
wrapper_.SetInstance(builder_.instance_object());
Handle<Code> wrapper_code = wrapper_.GetWrapperCode();
compiler::CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
wrapper_code, wrapper_.signature());
Handle<Code> wrapper_code = GetWrapperCode();
compiler::CodeRunner<int32_t> runner(main_isolate(), wrapper_code,
wrapper_.signature());
int32_t result;
{
SetThreadInWasmFlag();
......@@ -636,6 +640,19 @@ class WasmRunner : public WasmRunnerBase {
} \
void RunWasm_##name(TestExecutionTier execution_tier)
#define UNINITIALIZED_WASM_EXEC_TEST(name) \
void RunWasm_##name(TestExecutionTier execution_tier); \
UNINITIALIZED_TEST(RunWasmTurbofan_##name) { \
RunWasm_##name(TestExecutionTier::kTurbofan); \
} \
UNINITIALIZED_TEST(RunWasmLiftoff_##name) { \
RunWasm_##name(TestExecutionTier::kLiftoff); \
} \
UNINITIALIZED_TEST(RunWasmInterpreter_##name) { \
RunWasm_##name(TestExecutionTier::kInterpreter); \
} \
void RunWasm_##name(TestExecutionTier execution_tier)
#define WASM_COMPILED_EXEC_TEST(name) \
void RunWasm_##name(TestExecutionTier execution_tier); \
TEST(RunWasmTurbofan_##name) { \
......
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